保存WriteableBitmap的使用WPF到文件 [英] Save WriteableBitmap to file using WPF
本文介绍了保存WriteableBitmap的使用WPF到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
WriteableBitmap的BMP;
我basicly希望将其保存到像下面的磁盘上的文件:
C:\bmp.png
我看了一些论坛,其中提到为:
bmp.Pixels
和这些像素保存到位图
然后用位图。 SaveImage()
功能。但是,我不能访问任何像素
。 Apperantly我的 WriteableBitmap的
没有名为像素
的任何属性。
< 。p>我使用的.NET Framework 4.0
解决方案
使用您的WriteableBitmap的的克隆,使用如下此功能:
CreateThumbnail(文件名,_frontBitmap.Clone());
...
无效CreateThumbnail(字符串文件名,的BitmapSource图像5)
{
如果(文件名!=的String.Empty)
{
使用(的FileStream stream5 =新的FileStream(文件名,FileMode.Create))
{
PngBitmapEncoder encoder5 =新PngBitmapEncoder();
encoder5.Frames.Add(BitmapFrame.Create(图像5));
encoder5.Save(stream5);
}
}
}
I have:
WriteableBitmap bmp;
I basicly want to save it into a file on the disk like the following:
C:\bmp.png
I read some forums which mentions to read:
bmp.Pixels
and save those pixels into a Bitmap
then use Bitmap.SaveImage()
function. However, I can't access any Pixels
. Apperantly my WriteableBitmap
does not have any property named Pixels
.
I use .NET Framework 4.0.
解决方案
Use your WriteableBitmap's clone and use this function as below:
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);
}
}
}
这篇关于保存WriteableBitmap的使用WPF到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文