将WriteableBitmap导出为图像文件 [英] Exporting a WriteableBitmap as an image file
本文介绍了将WriteableBitmap导出为图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要导出剪切图像后得到的WriteableBitmap。我没有得到如何做到这一点,我使用以下内容:
Hi,
I need to export a WriteableBitmap that I get after cropping an image. I am not getting how to do that, I am using the following:
try
{
byte[] byteStream;
byteStream = ToByteArray(sample);
Stream stream = new MemoryStream(byteStream);
if (filename != null && filename != "")
{
string imgCropFileName = "Crop_" + DateTime.Now.Day + filename;
MessageBox.Show("FileName" + " " + imgCropFileName);
UploadFile(imgCropFileName, stream);
}
else
MessageBox.Show("FileName" + " " + filename);
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
在代码段中,ToByteArray是一个将WriteableBitmap转换为字节数组的函数。
用于上传,我正在使用一个通用的处理程序,当命中并获取相关参数时,上传文件。
请帮帮我。
In the code segment ToByteArray is a function to convert WriteableBitmap into array of bytes.
For uploading, I am using a generic handler which when hit and get relevant parameters, uploads the file.
Please help me.
推荐答案
这是由一个单独的类完成,其中一个派生类基于System.Windows.Media.Imaging.BitmapEncoder
。请参阅:
http:// msdn .microsoft.com / zh-cn / library / system.windows.media.imaging.bitmapencoder.aspx [ ^ ]。
实际上,这是一个非常好的WFP功能:持久性与图像隔离。如果你考虑一下,你会发现它有助于遵循基本的OOP开发开放/关闭原则:
http://en.wikipedia.org/wiki/Open_Closed_Principle [ ^ ]。
-SA
This is done by a separate class, one of the derived classes based onSystem.Windows.Media.Imaging.BitmapEncoder
. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapencoder.aspx[^].
Actually, this is a very good WFP feature: persistence is isolated from images. If you think about it, you will see that it helps to follow the fundamental OOP development Open/Close Principle:
http://en.wikipedia.org/wiki/Open_Closed_Principle[^].
—SA
这篇关于将WriteableBitmap导出为图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文