如何将byte []转换为图像并使用它 [英] How convert byte[] to image and use it
本文介绍了如何将byte []转换为图像并使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1245111111111111111111111111111111115555555555555555555555556666
我的尝试:
转换字节[] to image 4555519841199999998
1245111111111111111111111111111111115555555555555555555555556666
What I have tried:
Convert byte[] to image 4555519841199999998
推荐答案
using (var ms = new MemoryStream(byteArrayIn))
{
return Image.FromStream(ms);
}
请在此处查看JPG图片的答案: c# - 字节数组到图像转换 - 堆栈溢出 [ ^ ]
See answers here for a JPG image: c# - Byte Array to Image Conversion - Stack Overflow[^]
Rick是对的,直到某一点。但文档非常明确:
Rick is right, up to a point. But the documentation is very clear:
Quote:
您必须在图像的生命周期内保持流打开。
You must keep the stream open for the lifetime of the Image.
Image.FromStream方法(流) (System.Drawing) [ ^ ]
Image.FromStream Method (Stream) (System.Drawing)[^]
using (MemoryStream ms = new MemoryStream(byteArrayIn))
{
using (Image im = Image.FromStream(ms))
{
return new Bitmap(im);
}
}
更安全。
这篇关于如何将byte []转换为图像并使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文