WriteableBitmap bmp;
我basicly想將其保存到一個文件中像磁盤上的以下內容:
C:\bmp.png
我看了一些論壇,其中提到閱讀:
bmp.Pixels
並保存這些像素劃分爲Bitmap
然後使用Bitmap.SaveImage()
功能。但是,我無法訪問任何Pixels
。突然我的WriteableBitmap
沒有任何名爲Pixels
的屬性。
我使用.NET Framework 4.0。
WriteableBitmap bmp;
我basicly想將其保存到一個文件中像磁盤上的以下內容:
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);
}
}
}
它工作得很好,謝謝。 – Sait
真的有必要調用'stream.Close()'?不會'Dispose()'自動執行該操作? –
只是想提的是'WriteableBitmap.Pixels'是在Silverlight的屬性。它不可用於WPF- –
@AndersGustafsson感謝您的評論。我沒有意識到這一點。乾杯。 – Sait