当前位置:知识问问>百科知识>base64的byte[]如何转换成图片

base64的byte[]如何转换成图片

2024-09-18 15:04:49 编辑:join 浏览量:587

base64的byte[]如何转换成图片

在C#中

图片到byte[]再到base64string的转换:

Bitmap bmp = new Bitmap(filepath);

MemoryStream ms = new MemoryStream();

bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

byte[] arr = new byte[ms.Length];

ms.Position = 0;

ms.Read(arr, 0, (int)ms.Length);

ms.Close();

string pic = Convert.ToBase64String(arr);

base64string到byte[]再到图片的转换:

byte[] imageBytes = Convert.FromBase64String(pic);

//读入MemoryStream对象

MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);

memoryStream.Write(imageBytes, 0, imageBytes.Length);

//转成图片

Image image = Image.FromStream(memoryStream);

先得到byte[]、再转成ByteArrayInputStream

再用ImageIO写内存图片

static BufferedImage

read(InputStream input) Returns a BufferedImage as the result of decoding

a supplied InputStream with an ImageReader

chosen automatically from among those currently registered.

标签:base64

版权声明:文章由 知识问问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.zhshwenwen.com/article/384807.html
热门文章