News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Retrieving Color Data

Started by Bieb, March 19, 2005, 09:55:53 PM

Previous topic - Next topic

Bieb

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?

Tedd

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.)
No snowflake in an avalanche feels responsible.

Bieb

An example would be helpful.  Thanks for the help.

AeroASM

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.


Tedd

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 ::)
No snowflake in an avalanche feels responsible.

Bieb

How do I get the Bitmap handle exactly?  After I send the message, how will I retrieve the handle?

Bieb

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

raymond

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
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Bieb

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.

Bieb

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.

Tedd

No snowflake in an avalanche feels responsible.