使用WPF将WriteableBitmap保存到文件
我有:
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); } } }