Xyroid
Xyroid

Reputation: 463

saving canvas as image in metro style app with C#/XAML

I am developing a paint like application in metro style with C#/XAML. I want to save whatever content is drawn on canvas as image. I have checked this solutions but it didn't helped me.

Save canvas to bitmap http://blogs.msdn.com/b/saveenr/archive/2008/09/18/wpf-xaml-saving-a-window-or-canvas-as-a-png-bitmap.aspx

So how can I save the canvas content as image ? Please help me with sample coding.

Upvotes: 2

Views: 4566

Answers (4)

satur9nine
satur9nine

Reputation: 15042

The accepted answer from Sascha is no longer true for Windows 8.1. There is a new RenderTargetBitmap class that allows Rendered XAML to be converted to a bitmap.

See: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap.aspx

However I can't seem to render that XAML is Collapsed or otherwise not currently on screen. Any help with that would be appreciated!

Upvotes: 1

Sascha
Sascha

Reputation: 10347

It seems it is currently not supported out of the box like we were used to do it with WPF:

http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/dd66c749-efed-4b55-a716-e0aa3a637d28

While when doing HTML5/Javascript Metro apps you can do this:

http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/cf8c17dc-68d4-4777-951f-bb7f0665bd06

Upvotes: 0

Filip Skakun
Filip Skakun

Reputation: 31724

One workaround is to use Direct2D with DirectWrite. It is a bit involved, but I might make a library available at some point.

Upvotes: 0

Nigel Sampson
Nigel Sampson

Reputation: 10609

The standard approach in other xaml frameworks such as Silverlight and WP7 was to use WriteableBitmap, however the version in WinRT doesn't have a constructor that takes a xaml element which leads me to believe that it's currently impossible against the latest API.

Sorry I couldn't be more help/

Upvotes: 0

Related Questions