Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: How to convert BITMAP byte array to JPEG format?

Tags:

How can I convert a BITMAP in byte array format to JPEG format using .net 2.0?

like image 760
Marc Avatar asked Jan 19 '09 11:01

Marc


1 Answers

What type of byte[] do you mean? The raw file-stream data? In which case, how about something like (using System.Drawing.dll in a client application):

    using(Image img = Image.FromFile("foo.bmp"))     {         img.Save("foo.jpg", ImageFormat.Jpeg);     } 

Or use FromStream with a new MemoryStream(arr) if you really do have a byte[]:

    byte[] raw = ...todo // File.ReadAllBytes("foo.bmp");     using(Image img = Image.FromStream(new MemoryStream(raw)))     {         img.Save("foo.jpg", ImageFormat.Jpeg);     } 
like image 120
Marc Gravell Avatar answered Jan 01 '23 22:01

Marc Gravell