如何将字节数组转换为图像文件? [英] How to convert byte array to image file?

查看:86
本文介绍了如何将字节数组转换为图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的MVC网络应用中浏览并上传了png/jpg文件. 我已将此文件存储为byte []在我的数据库中. 现在,我想读取byte []并将其转换为原始文件. 我该如何实现?

I have browsed and uploaded a png/jpg file in my MVC web app. I have stored this file as byte[] in my database. Now I want to read and convert the byte[] to original file. How can i achieve this?

推荐答案

  1. 创建 MemoryStream ,将数组传递给构造函数.
  2. 使用 Image.FromStream从流中读取图像.
  3. 致电 theImg.Save("theimage.jpg",ImageFormat.Jpeg).
  1. Create a MemoryStream passing the array in the constructor.
  2. Read the image from the stream using Image.FromStream.
  3. Call theImg.Save("theimage.jpg", ImageFormat.Jpeg).

记住要引用System.Drawing.Imaging,并为流使用 using 块.

Remember to reference System.Drawing.Imaging and use a using block for the stream.

这篇关于如何将字节数组转换为图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆