从转换图像为Base64,为System.Drawing.Image [英] Conversion from image to base64, System.drawing.image
本文介绍了从转换图像为Base64,为System.Drawing.Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用C#的Windows Phone 8应用程序,我需要转换一个图像立足64.我用这个代码:
I use c# for windows phone 8 app and i need to convert one image to base 64. I use this code:
public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
但这个错误:
的命名并drwing它不是系统名称的空间中存在的类型名,也许没有一个集引用。
but it return this error: the name and the type of drwing name it isn't exist on the space of the system name, maybe there isn't an assembly reference.
我试图安装一个DDL ,但它也不行。
I try to install a ddl, but it's not ok.
推荐答案
您尝试使用无法在Windows Phone运行的代码,因为它使用的类从< 。code> System.Drawing中组装,这是不是此平台上
The code you try to use cannot work on Windows Phone, because it uses classes from the System.Drawing
assembly, which is not available on this platform.
尝试使用此示例代码:
public string GetBase64(Image image)
{
byte[] bytearray;
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap wb = new WriteableBitmap((BitmapImage)image.Source);
wb.SaveJpeg(ms, wb.PixelWidth, wb.PixelHeight, 0, 100);
bytearray = ms.ToArray();
}
return Convert.ToBase64String(bytearray);
}
这篇关于从转换图像为Base64,为System.Drawing.Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文