Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a byte array to PNG/JPG [closed]

Tags:

c#

png

jpeg

I am currently working on an application that requires high-performance conversion of an unpadded byte array to either a PNG or JPEG. The image format doesn't matter, just as long as it's fast.

I have tried the .NET libraries and the performance is very bad. Can anyone recommend a good freeware library for this?

EDIT: the byte[] is an 8bit grayscale bitmap

like image 690
user472875 Avatar asked Jan 20 '12 19:01

user472875


People also ask

How do I convert multiple images to PNG?

Open Finder and select the images you want to convert. Open them in Preview and then Select All. Go to "File" and choose "Export Selected Images". Choose the export format as PNG.

How do I change a File from JPG to PNG?

In Windows, open JPG in Microsoft Paint, and click File > Save as > PNG > Save. In Photoshop (Windows or Mac), go to File > Save as > Save as type > PNG > Save. Or File > Export > Export As > PNG > Export. In Preview on Mac, select File > Export > Export As > Format > PNG > Save.

How do I convert a bitmap to a byte?

In addition, you can simply convert byte array to Bitmap . var bmp = new Bitmap(new MemoryStream(imgByte)); You can also get Bitmap from file Path directly.


1 Answers

You should be able to do something like this:

using System.Drawing.Imaging; using System.Drawing; using System.IO;  byte[] bitmap = GetYourImage();  using(Image image = Image.FromStream(new MemoryStream(bitmap))) {     image.Save("output.jpg", ImageFormat.Jpeg);  // Or Png } 

Look here for more info.

Hopefully this helps.

like image 76
Garrett Vlieger Avatar answered Sep 24 '22 02:09

Garrett Vlieger