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;
或者,保存到隔离存储:
using (var isoFileStream = new IsolatedStorageFileStream("myPicture.jpg", FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication())) { wb.SaveJpeg(isoFileStream, myWidth, myHeight, 0, 100); }
- 在Windows中绑定Image.Source到String?
- 我可以绑定WinRT / Windows 8商店应用程序中的DynamicObject
- C#中的Google AnalyticsAPI – 请求执行失败:https://www.google.com/analytics/feeds/accounts/default
- 我如何在文件上执行SHA1哈希?
- 单击时,function区按钮不会触发由onAction设置的事件
- C#Linq或Lambda从类中获取Dictionary <string,List >
- 在ASP.NET页面中集成Microsoft Office Communicator 2007
- 表示2的补码中的hex值
- 以正确的顺序捕获进程stdout和stderr