Csharp/C#教程:UIElement to image file(WP7)分享


UIElement to image file(WP7)

我有一个StackPanel ,它包含一些我希望放入图像文件的Rectangles (例如PNG)。 我正在Windows Phone 7上开发这个,我在互联网上发现的大部分信息都不适用于WP7。

我认为System.Windows.Media.Imaging命名空间是关键,但我不知道从哪里开始。

这基本上就是我想做的事情:

 StackPanel stack = new StackPanel(); List recList = new List(); 

添加一些矩形到recList

 foreach(var x in recList) stack.Children.Add(x); 

然后将stackpanel保存到图像文件中……

您可以使用WriteableBitmap来保存图像。

 WriteableBitmap wb = new WriteableBitmap(stack, null); MemoryStream ms = new MemoryStream(); wb.SaveJpeg(ms, myWidth, myHeight, 0, 100); 

您可以将MemoryStream更改为隔离存储流。 如果要在Image控件中显示上述MemoryStream

  BitmapImage bmp = new BitmapImage(); bmp.SetSource(ms); image1.Source = bmp; 

或者,保存到隔离存储:

上述就是C#学习教程:UIElement to image file(WP7)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 using (var isoFileStream = new IsolatedStorageFileStream("myPicture.jpg", FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication())) { wb.SaveJpeg(isoFileStream, myWidth, myHeight, 0, 100); } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/957045.html

(0)
上一篇 2021年11月21日
下一篇 2021年11月21日

精彩推荐