我有:
WriteableBitmap bmp;
我基本上想将它保存到磁盘上的文件中,如下所示:
C:\bmp.png
我看了一些论坛,上面提到要阅读:
bmp.Pixels
并将这些像素保存到 Bitmap
中,然后使用 Bitmap.SaveImage()
函数。但是,我无法访问任何 Pixels
。显然我的 WriteableBitmap
没有任何名为 Pixels
的属性。
我使用 .NET Framework 4.0。
最佳答案
使用您的 WriteableBitmap 的克隆并使用此函数如下:
CreateThumbnail(filename, _frontBitmap.Clone());
...
void CreateThumbnail(string filename, BitmapSource image5)
{
if (filename != string.Empty)
{
using (FileStream stream5 = new FileStream(filename, FileMode.Create))
{
PngBitmapEncoder encoder5 = new PngBitmapEncoder();
encoder5.Frames.Add(BitmapFrame.Create(image5));
encoder5.Save(stream5);
}
}
}
关于c# - 使用 WPF 将 WriteableBitmap 保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11212771/