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

2020-02-13 02:30发布

问题:

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.

回答1:

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



回答2:

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!



回答3:

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/



回答4:

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