Page 1 of 1

Canvas to Bitmap

Posted: 12 Oct 2015, 18:03
by Genom
Hi guys, another question, is there any way to convert a canvas to an image? in standrd wpf I'd do something like this:
 Rect bounds = VisualTreeHelper.GetDescendantBounds(canvas);
            double dpi = 96d;


            RenderTargetBitmap rtb = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, dpi, dpi, System.Windows.Media.PixelFormats.Default);


            DrawingVisual dv = new DrawingVisual();
            using (DrawingContext dc = dv.RenderOpen())
            {
                VisualBrush vb = new VisualBrush(cnvs);
                dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
            }

            rtb.Render(dv);
(which comes from http://stackoverflow.com/questions/2141 ... -sharp-wpf)

Re: Canvas to Bitmap

Posted: 12 Oct 2015, 18:59
by jsantos
In Unity, you can user render to texture to generate a texture given a XAML.

Is that what you want?

Re: Canvas to Bitmap

Posted: 12 Oct 2015, 20:39
by Genom
I'm not sure, what I need is to get an image from a canvas where a user was printing with his finger (kind of signature)

can I do it through Unity render passing the canvas as param?

thanks!

Re: Canvas to Bitmap

Posted: 14 Oct 2015, 02:02
by jsantos
Render to texture is useful to capture a XAML into a texture. That texture can be later used in the same scene or even in another XAML.

But if you just need an image (not a texture) then I think the best way would be capturing the main buffer rendered by Unity. Never did it, but I am sure there should be an easy way to achieve.

Re: Canvas to Bitmap

Posted: 15 Oct 2015, 15:19
by Genom
Ok, then how could I pass just the canvas (not the whole screen or usercontrol) to unity to do it?

thanks!

Re: Canvas to Bitmap

Posted: 16 Oct 2015, 17:02
by jsantos
Yes, but the canvas cannot be shared between several Unity components. So, you need to create a NoesisGUIPanel component and set its content to a FrameworkElement (the canvas itself, not active in a different NoesisGUIPanel ). Attach the NoesisGUIPanel to a GameObject having a RenderTexture and the content of the canvas will be rendered into that texture.