c# - UIElement 到图像文件 (WP7)

标签 c# image-processing windows-phone-7 windows-phone uielement

我有一个 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 更改为独立存储流。如果要在 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);                    
}

关于c# - UIElement 到图像文件 (WP7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6299978/

相关文章:

matlab - 人体模特的服装剪裁

python - 如何在 OpenCV 中提取具有特定颜色的图像片段?

silverlight - 使图像控件根据主题反转其颜色

silverlight - 删除 silverlight 中按下按钮时突出显示的按钮

c# - Windows 服务 : check if base service is running

c# - 如何找出一些给定素数最接近 10000 的可能组合?

c# - 如何使用本地 WSDL 文件中的 Web 服务?

c# - 百万交易 - 提高网站性能

android - 使用 Android 阅读低对比度 (3D) 打印的二维码

c# - LongListSelector 和 ContextMenu 返回错误的项目