Creating a huge jpeg in code

Posted by: JeffS

Creating a huge jpeg in code - 08/09/2003 08:17

I’m working in Delphi (of course), but all I need to know is if this can be done at all in any language. I don’t necessarily need help with a solution, just knowing that it’s possible would be enough.

My problem:
In code, I have to create a jpeg image that can potentially be absolutely huge. The problem is that the only way I know of to draw to a jpeg is to first write to a bitmap in memory and convert it to jpeg before saving. The problem here is that I cannot create a bitmap large enough in windows without getting an “out of memory” error. I CAN break the image up into several smaller bitmaps, but I don’t know how to put these together in order to save as a single jpeg. Basically my problem is how to write a huge jpeg without creating a large bitmap in memory to do it.

Any thoughts?
Posted by: Dylan

Re: Creating a huge jpeg in code - 08/09/2003 08:45

You could save the bitmap to disk and call a command line program to convert. But that might not be possible depending on the situation.

We create large images in our app but decided to go with PNG instead of jpg. PNG is supported pretty much everywhere that jpg is and it doesn't have any licensing concerns. We use libpng in our C++ code.

http://www.libpng.org/pub/png/pngaptk.html

The above link shows PNG support available in Delphi in a number of different ways - including a libpng port.

-Dylan
Posted by: JeffS

Re: Creating a huge jpeg in code - 08/09/2003 09:02

The client wants JPG, so I really can't use a different format, though I will suggest PNG to him if you believe it will solve my problem.

As far a saving to disk first, I see two problems with that. The first is I have no idea how to draw a bitmap directly to disk (though certainly I could learn), the second is that this would be an absolutely huge file to process. Perhaps this would be ok, though. Do you have any suggestion on where I could look for how to draw bmps directly to file instead of memory (Delphi has a bunch of nice classes to do all of this for you, but none that write to a file instead of memory).
Posted by: wfaulk

Re: Creating a huge jpeg in code - 08/09/2003 09:38

Have you looked at this? I think it'll allow output directly to a file, although I'm not sure. But you can try it out for 30 days.
Posted by: JeffS

Re: Creating a huge jpeg in code - 08/09/2003 09:57

No, unfortunately it will still only allow you to save images first created in memory.
Posted by: JeffS

Re: Creating a huge jpeg in code - 08/09/2003 10:02

Ok, I just had a flat forhead moment!

This bitmap has like 16 colors and I'm saving it in the default pixel format (number of colors). If I lower the pixel format down I should be able to write to the bitmap just fine!

Sorry for the thread folks. Move along, nothing to see here . . .
Posted by: peter

Re: Creating a huge jpeg in code - 08/09/2003 10:21

This bitmap has like 16 colors and I'm saving it in the default pixel format (number of colors). If I lower the pixel format down I should be able to write to the bitmap just fine!
The image has 16 colours, and the client requires it to be a JPEG? Sounds like it shouldn't be your forehead you should be slapping.

Peter