[英]UIElement to image file (WP7)
我有一个StackPanel
,其中包含一些我想放入图像文件(例如 PNG)的Rectangles
。 我正在 Windows Phone 7 上开发这个,我在互联网上找到的大部分信息都不适用于(我认为)WP7。
我认为System.Windows.Media.Imaging
命名空间是关键,但我不知道从哪里开始。
这基本上是我想要做的:
StackPanel stack = new StackPanel();
List<Rectangle> recList = new List<Rectangle>();
向recList
添加一些矩形
foreach(var x in recList)
stack.Children.Add(x);
然后将堆栈面板保存到图像文件...
您可以使用WriteableBitmap
来保存图像。
WriteableBitmap wb = new WriteableBitmap(stack, null);
MemoryStream ms = new MemoryStream();
wb.SaveJpeg(ms, myWidth, myHeight, 0, 100);
您可以改为将MemoryStream
更改为独立存储 stream。 如果要在 Image 控件中显示上述MemoryStream
:
BitmapImage bmp = new BitmapImage();
bmp.SetSource(ms);
image1.Source = bmp;
或者,保存到独立存储:
using (var isoFileStream = new IsolatedStorageFileStream("myPicture.jpg", FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication()))
{
wb.SaveJpeg(isoFileStream, myWidth, myHeight, 0, 100);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.