Board index » delphi » How do I get DIB from TBitmap?

How do I get DIB from TBitmap?

Hi Everyone,

I'm using TBitmap to load a 256-color (8-bit) bitmap from a file. I then
want to work with the individual pixels and am trying to use the GetDIBits
function, but it returns the bitmap as a device dependent bitmap (16-bit
when my display is in 16-bit mode, etc.). I know for a fact that the bitmap
is only 8-bit, so what can I do to get to the normal bits and palette?

Thanks,
Theodor

____________________________________________
theo...@gem.co.za
http://members.gem.co.za/~theodor/index.html
+27-21-9132479 (tel & fax)

 

Re:How do I get DIB from TBitmap?


Quote
Theodor Kleynhans wrote:

> Hi Everyone,

> I'm using TBitmap to load a 256-color (8-bit) bitmap from a file. I then
> want to work with the individual pixels and am trying to use the GetDIBits
> function, but it returns the bitmap as a device dependent bitmap (16-bit
> when my display is in 16-bit mode, etc.). I know for a fact that the bitmap
> is only 8-bit, so what can I do to get to the normal bits and palette?

> Thanks,
> Theodor

> ____________________________________________
> theo...@gem.co.za
> http://members.gem.co.za/~theodor/index.html
> +27-21-9132479 (tel & fax)

Theodor,

Easiest way is to create a TMemoryStream, write the bitmap into the
memorystream, read past the bitmap header info, store the color palette
info and then move the rest of the stream into an array of bytes.  Then
process the heck out of the pixel values, rewrite any changed color
palette values and the new pixel byte values back into the memorystream
and save to the (new) bitmap file.

Derek

PS  GetDIBxxxx is just doing it's job which is to handle DIB->DDB
conversion.

Other Threads