Manually crating JPG file from array of bytes

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hello.

I need to create JPG file base on data from some array of bytes without
using any graphical functions.
So I need the function which will get array of bytes as parameter and write
it byte by byte into file, of course there must be inserted all necessary
data appropriate of JPG format (headers compression and etc...).
Can anybody show me how can I implement such function?
Also does anybody know where can I find detailed information about JPG
compression algorithm?

Thank you.
 
David,

I would ask why you can not use any graphical functions?

That aside, what kind of information is in the byte array? It obviously
isn't in a JPG format already, because if it was, you could just save the
whole byte array to disk and be done with it.
 
Try creating an Image object from the byte array first, something like:

MemoryStream ms = new MemoryStream(myByteArray);
Image i = Image.FromStream(ms);
i.Save("i.jpg", ImageFormat.Jpeg);

It might work if the initial byte array was created from image data.
Otherwise you will need to encode it yourself. There are many reference
implementations of jpeg encoding but you can always start here:
http://www.ijg.org/

ok,
aq
 
Back
Top