Efficiency of Using PNG's vs. BMP's With Large Files

Go To StackoverFlow.com

8

I've written a mapping program in Delphi where the user can load a raster image in the background which I store in memory. In one case the user loaded a 44MB BMP successfully but the program was sluggish and when they printed (I tile the output) they got an Out Of Resources error. I converted the BMP to a PNG (3MB) and the program performs much better and the print job was successful.

Since the PNG has to be expanded to a DIB of the same size anyway why is there a performance/resource difference? If anything it should take more work and memory allocations to load the PNG. What am I missing?

Since there don't seem to be any obvious answers I'll write a small demo project so I can research this further.

2012-04-05 16:53
by Mitch
Are you positive the BMP and PNG files have the same number of pixels and BitsPerPixel - François 2012-04-05 17:05
What you are using to print the image? Are you writing directly on the Printer.Canvas or you are using a component on a report like QuickReport or Rave - rkawano 2012-04-05 17:19
Francois: Yes, I got the customers file and tried it myself. rkawano: I print to DIB tiles that I send to the printer canvas - Mitch 2012-04-05 19:29
Sounds like you have yourself a memory leak somewhere - MickLH 2013-11-26 14:41


1

The difference is compression.

BMP = raw data as is PNG = same raw data using "lossless" compression

This has a saving in more than 1 way in programming circles ...

  1. loading the image results in loading less raw data in to ram.
  2. You are then processing less raw data so you need less resource.

Tiling means the problem for you is exponential for example ...

44MB x 10 tiles = 440MB

Vs

3MB x 10 tiles = 30MB

Printers don't like being handed massive chunks of data and all but the more expensive printers tend to like to print and entire document in one go (eg buffer the whole stream).

So from your app the user says "Print" ... your code then says "right i'm gonna send 10 copies of this" and the printer starts "caching" 440MB of raw data.

Most common home printers rely on the pc to do the caching and print what it's given but a standard office printer will do the caching then print the doc.

However ... i think this is an optional thing you can tweak (i'm thinking it varies from printer to printer though).

EDIT:

heres something from the world of game programming:

http://www.gamedev.net/topic/450104-png-vs-bmp/

2012-04-12 13:35
by War
In tracing through the code the PNG is expanded to a DIB of equal size to the BMP in memory. I suppose more memory efficient code would do the conversion as needed - Mitch 2012-04-12 16:16
Are you saying that tiling doesn't help? I draw a portion to the tile, at device resolution, which is then passed to the printer. I'd draw directly and let the printer driver handle it but then I'd lose the ability to do transparency - Mitch 2012-04-12 16:21
im not entirely sure what you are doing but the basic concept is that every chunk of that image you send to the printer it has to process and it has to do this as uncompressed "raw" data usually. This mightb e the cause of your resource issue ... resource on the printer not on the computer ... does that make sense - War 2012-04-13 08:14
Not really, the tiling sends the same amount of data (DIB) whether the original image was PNG or BMP. As a matter of fact both images are stored by the library I'm using in memory as Device Independent Bitmaps (DIB). That's why this whole issue makes no sense - Mitch 2012-04-13 21:19
hmmm odd ... ok it's not what i thought it was .. - War 2012-04-16 16:03
Ads