Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c#: Saving JPGs in parts

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

like image 379
mgulde Avatar asked Nov 25 '11 09:11

mgulde


1 Answers

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

like image 108
Emir Akaydın Avatar answered Oct 10 '22 08:10

Emir Akaydın