Converting XAML into an image in Windows Phone?

匆匆过客 提交于 2019-12-13 02:23:33

问题


For Windows Phone 8, I am looking for a way of converting XAML into an image. Is that possible? I have made a custom control in XAML mixing elements such as images and so forth, that I would like to programmatically "take a screenshot of" and save it.

The reason for this is that I'm trying to customize the lockscreen in my very own way.


回答1:


Use the WriteableBitmap class.

From MSDN:

Generate a bitmap snapshot of a visual tree starting from any UIElement:

  • Construct a WriteableBitmap using WriteableBitmap.WriteableBitmap.
  • To display the image in UI, use the WriteableBitmap as the source for an imaging control such as Image, or as the source image for an ImageBrush.
  • If you want to render the bitmap multiple times and reuse the instance for additional snapshots, use the Render method. You will need to call Invalidate after Render to render the new image.
  • You have the option to preserve any existing RenderTransform on the UIElement by passing the transform to the constructor, or canceling any existing transform by passing an identity transform or null.



回答2:


You can find one of the sammple how to do it on Nokia Wiki page (XAML as User control) so I think it could help: Custom Layout for Tile



来源:https://stackoverflow.com/questions/17511489/converting-xaml-into-an-image-in-windows-phone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!