I've been searching for some code that could teach how to, having a bitmap stored in memory, access to each of its pixels.

Surely it is a nosense, but I don't know how... :(

Thanks in advance.
Posted on 2001-12-18 17:58:24 by Theopulus
I don't mean using SetPixel or so, but having a memory array where I could apply any effect.

Thanks again.
Posted on 2001-12-18 18:13:09 by Theopulus
Afternoon, Theopulus.

You could use "CreateDIBSection". It returns a pointer (the fourth param) to the bitmaps' bits.

Cheers,
Scronty
Posted on 2001-12-18 23:44:16 by Scronty
I will try this one
Posted on 2001-12-19 03:00:45 by Theopulus
You can find an example in my LCD program, it's in masm32 v7 (EXAMPLE6\LCD).

Thomas
Posted on 2001-12-19 03:31:18 by Thomas
After reading your example, I've tried this code

CreateBMP PROC hWnd:HWND
LOCAL hDC:DWORD

invoke GetDC, hWnd
mov hDC,EAX
invoke CreateCompatibleDC,hDC
mov hLCDDC,EAX
invoke CreateDIBSection,hDC,\
ADDR BITBITMAPINFO,\
DIB_RGB_COLORS,\
ADDR lpLCDBmp,\
NULL,NULL
mov hLCDBitmap,EAX
ret
CreateBMP ENDP

Drawit PROC hWnd:HWND
LOCAL hDC:DWORD

invoke GetDC, hWnd
mov hDC,EAX

push EDI
CLD
MOV EDI,lpLCDBmp
mov EAX,1
mov ECX,6400
rep stosb
pop EDI

; Copy to my window

invoke SelectObject,hLCDDC,hLCDBitmap
invoke BitBlt,hDC,0,0,320,240,hLCDDC,0,0,SRCCOPY
ret
Drawit ENDP

But it doesn't seem to work .What is there wrong? Everything?

Thanks in advance
Posted on 2001-12-19 16:47:21 by Theopulus
1. A GetDC call should always match a ReleaseDC call.
2. Does it blit anything? What does it look like?
3. How did you define BITBITMAPINFO?
(4. Not a problem with your code but good to know: data for one line of the bitmap should always be a multiple of 4 bytes, so if you don't have that after one line is done, pad with zeroes until you've reached a number dividable by 4. You won't have this problem when using a width of 320 though.)

Thomas
Posted on 2001-12-20 10:29:50 by Thomas
In this piece of code:

PUSH EDI
CLD
MOV EDI,lpLCDBmp
MOV EAX,1
MOV ECX,6400
REP stosb
POP EDI

I try to write 6400 bytes to the address pointed by lpLCDBmp, which is the pointer addressed by CreateDIBSection.

By the way, I use the same piece of code as your LCD example.

But instead of that, it fills "sometimes" with a full green screen, sometimes with a black one. I don't understand what is wrong
Posted on 2001-12-20 15:38:31 by Theopulus
Afternoon, Theopulus.

I've attached a little proggy which creates a font-bitmap with a DIB (6kb zip)

It's a bit rough, and there aren't many comments.
Just follow the CreateFontBitmap proc. It's might be similar to Thomas' example, so you can compare the two and see what's missing.

The easiest way to re-assemble this proggy, is to use Hutchs' QEditor and select "project->Build All".

Cheers,
Scronty
Posted on 2001-12-21 00:40:03 by Scronty
What color type are you using? Have you initialized a palette?

Thomas
Posted on 2001-12-22 05:16:29 by Thomas
Maybe this has been my problem. Palette... I thought that I didn't have to initialize. Maybe lack of knowledge :)
Posted on 2002-01-05 08:02:40 by Theopulus
The BITMAPINFO struct pointer you have to pass to createdibsection is folllowed by the palette in the form of an RGBQUAD array (blue byte, green byte, red byte, reserved byte, blue byte....).
If you are using an image of at least 16bpp there is no palette.

Thomas
Posted on 2002-01-05 10:58:42 by Thomas