News:

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

Draw Bitmap

Started by raleeper, July 12, 2007, 11:34:22 AM

Previous topic - Next topic

raleeper

I am looking for a function that draws, paints, or outs a bitmap.  I imagine that what I need is something like this:


BitmapOut   proto hdc:DWORD,lpBMADR:DWORD,cbBMSZ:DWORD,lpRin:DWORD,lpRout,fALIGN:DWORD
   ;Parameters:
;hdc      Handle to device context
;lpBMADR   Address of start of bitmap
;cbBMSZ      Size of bitmap in bytes
;lpRin      Pointer to rect structure in which bitmap is to be drawn
;lpRout      Pointer to rect structure to receive largest sub-rectangle in which the operation can be done
;fALIGN      Flag specifying alignment methods
;Returns:   1   failure - bitmap cannot be aligned for lpRin
;         lpRout has valid values; nothing is drawn or outed
;      0   failure - all other types
;      else   success

;Remarks:   Values in lpRout are unchanged or invalid unless return = 1.
;      fALIGN flags are to be defined based on what is available.

So far I am not finding anything in the SDK like this or much that looks like it could be used to do something similar - although possibly some brush functions might be adapted.

Can anyone suggest how I might procede from here?

Thanks.

japheth


Hi,

a fast GDI method to draw bitmaps is using function SetDIBitsToDevice(). However, it's a bit "advanced" with its many parameters.


gabor

Hello!

I would recommend the BitBlt function also. Maybe it is a bit inconvinient to use, because it uses device contexts (HDCs) so, first a compatible DC has to be created for the source bitmap and for the target (I suggest the target, for example the display has its own DC already).
Like this:

invoke CreateCompatibleDC,hDC ; create DC compatible with the desired context: hDC
mov hSourceBitmapDC,eax
invoke SelectObject,hSourceBitmapDC,hBitmap ; select bitmap to be coopied into context
mov hOldBitmap,eax ; possibly unnecessary to store old value, see below

invoke BitBlt,hDC,dwXPos,dwYPos,dwWidth,dwHeight,hSourceBitmapDC,0,0,SRCCOPY ; copy source into destination

invoke SelectObject,hSourceBitmapDC,hOldBitmap ; possibly unnecessary since the DC is destroyed in the next row :)
invoke DeleteDC,hSourceBitmapDC ; destroy bitmap DC


This should work, more or less. My original code with some modifications works.

Greets, Gábor

japheth

> I would recommend the BitBlt function also.

Yes, your code will also work. However, you forgot to tell where the hBitmap is coming from. If you don't have a hBitmap, but just some color data, you will first need to call CreateDIBitmap() to get a DDB handle. That is, 6 functions have to be called, compared to just 1 by using SetDIBitsToDevice.

raleeper

Yes! Thanks, Japeth and Gabor!  This appears to be exactly what I was looking for.

There is a lot to be done and so far I am only about 3% into it, but it all looks doable.

1.  The most time-consuming and tedious part is going to be defining all the individual character image bitmaps.  I have done this before for monochrome - on my very first computer, a Timex-Sinclair 2048(?), a z80 machine with about 32k of user memory.  I'll probably want to use BitBlt to retrieve, decypher, modify and use what DrawText puts on the screen when fed a string consisting of the 100 bytes, 0..0FF.

2.  What I missed the first time I read your posts was that while BitBlt only copies from one device to another, ypu can define one device to be (essentially) a block of memory.

3.  The big remaining windows API mystery is how to relate pixel-based coordinates and dimensions to the "logical units" returned by getclientrectangle and used by the drawing functions, but I'm sure I'll find the answer to that one - maybe in the documentation for GetSystemMetrics, maybe in Petzold.

4.  I'm finding the SDK documentation to be not very useful, except as a final check.  Petzold (Programmimg Windows, 5th ed., Microsoft Press, 1999) on the other hand, seems excellent from a beginner's perspective.  (Hey Charles! Please do a concise assembly version.)

I'll have to go slow for a while because my !@#$ Asus motherboard has trashed another hard drive - the one I was keeping almost all my windows programming stuff on.  I'm hoping to recover most of the data, but that will take some time.

Thanks and best wishes,

raleeper (Robert Allen Leeper)