Manually crating JPG file from array of bytes

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

Nicholas Paldino [.NET/C# MVP]

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

Ahmed Qurashi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top