c#: Saving JPGs in parts
Asked Answered
P

1

6

I am currently working on a c# open source photo mosaic software (Sourceforge Link). This software stitches together large amounts of small photos (tiles) into one big image.

Since the final image size is usually in the order of 20k px times 15k px, I am only saving a map of how to arrange the tiles in memory. To construct the final image, I am constructing it in parts, namely in band of 8 lines (can by any other number, too).

In the case of bmps, this data can then easily saved chunk by chunk by first writing a bmp header and subsequently appending the ARGB data to this file.

But the resulting bmps are far too big for further handling (e.g. giving them to some poster printing company). I would therefore like to save these big images as jpgs on my hdd.

The problem is now, that since jpgs are compressed, writing the data in chunks seems very tricky (the normal Bitmap.Save() function will load the full image into memory first and is therefore not applicable), since writing pure, uncompressed RGB data won't do it.

The basic functionality of writing jpgs in party should exist, since as far as I know the compression algorithm of jpg works with chunks or 8x8 px.

I looked into several image libraries (FreeImage, GraphicsMagick, LibTiff.NET) to find solutions for this problem, but could not find any. LibTiff basically has the desired functionality, but only for the tiff image format.

Thanks a lot for your help! Max

Peewit answered 25/11, 2011 at 9:45 Comment(0)
J
1

Since you didn't mention OpenJPEG library, I thought you may have missed it.

http://www.openjpeg.org/

Of course you will need some wrappers around it but I think you can achieve what you want to do using that library. But this is not the easiest solution, I know. If someone else comes up with a better, easier suggestion, you can skip this library.

Edit: This looks very incomplete but may be helpful since it's C# code. http://www.codeproject.com/KB/graphics/SimpleJpeg.aspx

Jones answered 25/11, 2011 at 10:5 Comment(3)
Thanks, I indeed missed it. Will check it out asap!Peewit
Hmm, turn out OpenJPEG is basically only for JPEG to JPEG2K conversion and back. The simple encoder is a nice solution, even though it looks mighty complicated ;)Peewit
Hmm, does the openjpeg library support incremental I/O? I looked at it a bit (though the docs are very minimal), and all the image I/O interfaces seemed to operate only on complete images... Can you point out the API calls one uses to do incremental I/O with the openjpeg library...? Thanks!Retool

© 2022 - 2024 — McMap. All rights reserved.