Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert byte array to image file?

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?

like image 878
Jaqen H'ghar Avatar asked Jun 23 '10 13:06

Jaqen H'ghar


People also ask

What is byte array image?

Images are binary data - this is easily represented as byte arrays. The image in the sample is stored in the database as a BLOB - not a string or location, that is, it is binary data.

How do I print a byte array?

You can simply iterate the byte array and print the byte using System. out. println() method.


1 Answers

  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).

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

like image 179
Gelatin Avatar answered Oct 13 '22 01:10

Gelatin