问题
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