Genom
Topic Author
Posts: 47
Joined: 04 Dec 2014, 14:47

Canvas to Bitmap

12 Oct 2015, 18:03

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)
 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: Canvas to Bitmap

12 Oct 2015, 18:59

In Unity, you can user render to texture to generate a texture given a XAML.

Is that what you want?
 
Genom
Topic Author
Posts: 47
Joined: 04 Dec 2014, 14:47

Re: Canvas to Bitmap

12 Oct 2015, 20:39

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!
 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: Canvas to Bitmap

14 Oct 2015, 02:02

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.
 
Genom
Topic Author
Posts: 47
Joined: 04 Dec 2014, 14:47

Re: Canvas to Bitmap

15 Oct 2015, 15:19

Ok, then how could I pass just the canvas (not the whole screen or usercontrol) to unity to do it?

thanks!
 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: Canvas to Bitmap

16 Oct 2015, 17:02

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.

Who is online

Users browsing this forum: No registered users and 0 guests