The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Bieb on March 19, 2005, 09:55:53 PM

Title: Retrieving Color Data
Post by: Bieb on March 19, 2005, 09:55:53 PM
Hi all.  I've gotten my bitmap saving problem solved except for one thing.  Up till now, I've been retrieving the color data using the GetPixel API call.  Problem is, that's taking forever.  What's the best way to get the color data from a Static control into a buffer in memory I can write to a bitmap?
Title: Re: Retrieving Color Data
Post by: Tedd on March 21, 2005, 11:57:50 AM
You need to mess about with CreateDIBSection and such, which will get you a pointer to the start of the bitmap data. From that you can then access whichever pixels you like directly.
(I'll post an example tomorrow if you need it.)
Title: Re: Retrieving Color Data
Post by: Bieb on March 21, 2005, 05:04:29 PM
An example would be helpful.  Thanks for the help.
Title: Re: Retrieving Color Data
Post by: AeroASM on March 21, 2005, 07:40:25 PM
That sounds perfect for your RGG, because having gotten a pointer to the DIB, all you need to to is write the BFH, BIH and DIB to the file.
Title: Re: Retrieving Color Data
Post by: kero on March 22, 2005, 07:09:40 AM
It isn't easy to help the guy if he doesn't read answers...

(http://www.masmforum.com/simple/index.php?topic=998.0,
http://www.masmforum.com/simple/index.php?action=dlattach;topic=998.0;id=495)
Title: Re: Retrieving Color Data
Post by: Tedd on March 22, 2005, 12:14:52 PM
Okay, so this isn't an example - didn't get chance :P

It looks like you should be okay to use the GetDIBits function.
- you already have the DC handle (hDC)
- to get the bitmap handle (hBmp) from a static control send it STM_GETIMAGE
- the other params should be pretty straighforward if you can manage to create a bitmap :wink

This all assumes that you don't already have the bitmap that's in the static control; otherwise it's a bit of a long way around it.

Anyway, any problems - just shout ::)
Title: Re: Retrieving Color Data
Post by: Bieb on March 25, 2005, 08:07:01 PM
How do I get the Bitmap handle exactly?  After I send the message, how will I retrieve the handle?
Title: Re: Retrieving Color Data
Post by: Bieb on March 26, 2005, 08:49:22 PM
I've tried the following code, using an HDC in memory and the handle of the bitmap I selected into it.


.data
JackedHeader DB 42H, 4DH, 0F6H, 76H, 8H, 0, 0, 0, 0, 0, 36H, 0, \
0, 0, 28H, 0, 0, 0, 0ACH, 01H, 0, 0 , 0B0H, 01H, 0, 0, 01H, 0, 18H, \
  0, 0, 0, 0, 0, 76H, 08H

...

SaveBitmap Proc Private
Local GarbageDW:DWord
Local FileHandle:DWord
Local BmpInf:BITMAPINFO
Local MemHandle:DWord
Local MemPointer:DWord
Invoke CreateFile, Addr FilePath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
Mov FileHandle, Eax
Invoke WriteFile, FileHandle, Addr JackedHeader, 36H, Addr GarbageDW, NULL
Invoke GlobalAlloc, GMEM_MOVEABLE, 554688
Mov MemHandle, Eax
Invoke GlobalLock, MemHandle
Mov MemPointer, Eax
Invoke GetDIBits, BufferHandle, BitMapHandle, 0, 432, MemPointer, Addr BmpInf, DIB_RGB_COLORS
Invoke WriteFile, FileHandle, MemPointer, 554688, Addr GarbageDW, NULL
Invoke GlobalFree, MemHandle
Invoke CloseHandle, FileHandle
Ret
SaveBitmap EndP
Title: Re: Retrieving Color Data
Post by: raymond on March 27, 2005, 04:53:52 AM
It would be a lot easier on you to declare the BMP header with variable names instead of working out the bytes by hand.

JackedHeader db "BM"
BMsizeLow    dd ?
BMsizeHi     dd 0
RGBoffset    dd ?
bi    BITMAPINFOHEADER <>

You can then fill the required data from your program.

Raymond
Title: Re: Retrieving Color Data
Post by: Bieb on March 28, 2005, 06:39:00 PM
I actually just ripped that header out of a premade bitmap file.  That works fine, it's just actually getting the bitmap itself that i'm having trouble with.
Title: Re: Retrieving Color Data
Post by: Bieb on March 28, 2005, 09:28:13 PM
Once again, a stupid mistake on my part.  Apparently I'm supposed to fill out a BITMAPINFO structure and pass it's adress, not just pass the adress of an empty structure to be filled out.  Once I did that, it worked nicely.  Thanks for the help.
Title: Re: Retrieving Color Data
Post by: Tedd on March 29, 2005, 10:19:08 AM
RTFM :bdg

:cheekygreen: