I did, but it seemed to be beyond my abilities.

I think you could handle it. But you don't have to -- since I am going
to need this same facility soon, I went ahead and coded it up as a
demo project:

 http://ljensen.com/misc/Demo_SaveAsBMP.rbp.zip

It seems to work well on Mac using RB2007r1. I haven't tested it on
Windows yet but I expect it to work there too. It could easily be
extended with optional arguments for bit depth, alpha channel support,
resolution, etc.

Here are some notes to set the stage.

For a 24-bit BMP file with no alpha channel, the file looks like this:

 2 bytes = "BM"
 4 bytes = size of file
 4 bytes = 0 (reserved)
 4 bytes = 54 (starting position of image data)

 4 bytes = 40 (size of rest of header)
 4 bytes = image width (pixels)
 4 bytes = image height (pixels)
 2 bytes = 1 (count of planes)
 2 bytes = 24 (bits per pixel)
 4 bytes = 0 (compression type)
 4 bytes = pixel data byte count = height * bytes per line
 4 bytes = 2834 (horizontal resolution in pixels per meter)
 4 bytes = 2834 (vertical resolution in pixels per meter)
 4 bytes = 0 (color count)
 4 bytes = 0 (important color count)

The rest of the file is the pixel data itself.

There are a few gotchas to be aware of:

1) The above numbers need to be written in LittleEndian byte order.
2) The pixel data is written in BGR order, not RGB as one might expect.
3) Each row of pixel data is padded to a multiple of 4 bytes in length.
4) The pixel data starts with the bottom row of pixels and proceeds to
the top row.

Also, if you use other programs to create test BMP images to compare
this output to, be aware that some versions of Photoshop Elements
append an extra 2 bytes to the end of the file, and that some
applications (such as Apple Preview?) calculate a resolution value for
72 DPI that is off by one from mine due to differences in integer
rounding.

lj
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to