我有一个StackPanel
其中包括一些Rectangles
我想将其放入图像文件(例如 PNG)。我正在 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
改为隔离存储流。如果你想显示上面的内容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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)