8 Responses to “Simple C/C++ JPEG Writer Part 2 – Write to Buffer in Memory”

  1. pestek says:

    Hello,

    I downloaded this source and needed libs. I can debug this program. I have message: “JPEG parameter struct mismatch: library thinks size is 360, caller expects 371”. Could you help me solve this problem?

    Regards,

  2. aewhite says:

    I have never seen this error in person. It looks like the library is doing a sanity check where it asserts sizeof(lib_struct) == sizeof(compiled_struct). In other words, I would guess you complied your program using headers from version X and your program is linking against version Y.

  3. ben says:

    Hey,

    do you have an example for decompressing the jpeg image to an in-memory buffer too? I found your example very helpfully for compressing the data but now I want to get it back to the source format

    Regards

  4. aewhite says:

    I do not, mostly because it depends on the context in which you need to decompress. For games there is libSDL, for graphics processing there is ImageMagick, and depending on your platform there could be a number of special purpose readers.

  5. eGO says:

    Hi,

    Thanks for your post(s)! I want to ask you if it is there a way of resizing an image. I tried to change the width and height values from the cinfo struct before writing the new image, but with no luck. The result is a totally mess – a flipped corner, smtg like that.

    Thanks!

  6. aewhite says:

    I never played with that so I am not going to try to tell you how to do it wrong :) Take a peek at StackOverflow and see if they can help you out.

  7. Stefan says:

    This helped a lot, thank you! Worked nearly at once!

    But you swaped the size in bytes of each element and their number in fwrite (on my pc just one byte has been written).

  8. aewhite says:

    Looking back, that fwrite code doesn’t look right. It should at least check the return to be sure the number of bytes written is correct. I suspect it should work on files smaller than 64k (block size) though.