字节数组到位图图像 [英] byte array to Bitmap images
本文介绍了字节数组到位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要代码将图像的字节数组转换为位图图像。任何人请帮助
当我写这样的代码我得到一个错误,如参数无效
I need the code to convert a byte array of image to bitmap image.Anybody please help
when i write code like this i got an error like Parameter is not valid
private Bitmap BytesToBitmap(byte[] byteArray)
{
Bitmap imageFile = new Bitmap(new MemoryStream(byteArray));
return imageFile;
}
字节数组是指图像。
第一个语句中引发的异常
byte array refers image.
The exception thrown in first statement
推荐答案
看看这里:
为什么我得到参数无效。我从数据库中读取图像时出现异常? [ ^ ]
如果你可以使用Image
而不是Bimap
Try below if you can useImage
instead ofBimap
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
这篇关于字节数组到位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文