This project is read-only.

Create An Image With All Children Contained In a Canvas

Mar 20, 2013 at 9:40 PM
Hi guys, I'm trying to get all children I've added into a Canvas and create a single image from it. Is it possible?
Mar 21, 2013 at 9:04 AM
Is that for WinRT or which platform?
If it's non-WinRT you can just use the following snippet to render it out:
new WriteableBitmap(myCanvas, null)
Otherwise you can blit all those Children images to a destination using the Blit method.
  • Rene
Mar 21, 2013 at 12:04 PM
Edited Mar 21, 2013 at 12:04 PM
Yes, it's for WinRT. So, using this Blit method, I can output all images I have in my canvas, in the same position???
Can you give me an example?

Mar 21, 2013 at 1:18 PM
Here you go:
var destBmp = BitmapFactory.New((int) myCanvas.ActualWidth, (int) myCanvas.ActualHeight);
foreach (var child in myCanvas.Children)
    var img = child as Image;
    if (img != null)
        // Assuming you have WBs as Source, if not use:
        // var scrcBmp = new WriteableBitmap(0, 0).FromStream(...);
        var srcBmp = img.Source as WriteableBitmap;
        if (srcBmp != null)
            var x = Canvas.GetLeft(img);
            var y = Canvas.GetTop(img);
            destBmp.Blit(new Rect(x, y, srcBmp.PixelWidth, srcBmp.PixelHeight), srcBmp, new Rect(0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight));
  • Rene
Mar 21, 2013 at 10:59 PM
Edited Mar 21, 2013 at 10:59 PM
Thanks, it worked almost 100%.