News:

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

Displaying bitmaps from memory

Started by Vortex, September 25, 2005, 01:03:26 PM

Previous topic - Next topic

Vortex

Here is another example of displaying bitmaps from memory using CreateDIBitmap :
.IF uMsg==WM_CREATE
      invoke GetDC,hWnd
      push eax
      lea ecx,[pBitmap+sizeof(BITMAPFILEHEADER)] ; start of BITMAPINFOHEADER header
      mov edx,OFFSET pBitmap
      mov eax,DWORD PTR [edx+10]
      add edx,eax  ; BITMAPFILEHEADER -> bfOffBits
      pop eax
      invoke CreateDIBitmap,  eax, ecx,CBM_INIT,edx,ecx,DIB_RGB_COLORS
      mov hBitmap,eax
         
   .ELSEIF uMsg==WM_PAINT
      invoke BeginPaint,hWnd,ADDR ps
      mov hdc,eax
      invoke CreateCompatibleDC,eax
      mov hMemDC,eax
      invoke SelectObject,eax,hBitmap
      lea edx,[pBitmap+sizeof(BITMAPFILEHEADER)] ; start of BITMAPINFOHEADER header

      ASSUME edx:ptr BITMAPINFOHEADER

      invoke BitBlt,hdc,0,0,[edx].biWidth,[edx].biHeight,hMemDC,0,0,SRCCOPY
      invoke DeleteDC,hMemDC
      invoke EndPaint,hWnd,ADDR ps

[attachment deleted by admin]

Gustav

Vortex,

this code works fine, but I would suggest to modify it slightly so that bitmaps without the BITMAPFILEHEADER could be displayed as well (to be able to display bitmap resources). The only "problem" then is to calculate the size of the color table, which comes just behind the BITMAPINFOHEADER structure, but it's trivial: either the clrUsed value is to be used or, if this field is zero, the size is 2*4 for 1bpp, 16*4 for 4bpp, 256*4 for 8bpp, 0 for other bpps.

Regards

Vortex

Hi Gustave,

Thanks for the suggestion. My aim is to display bitmaps without using resources. Loading bitmap from binary data as in my example allows you to encrypt easily bmp images.

Farabi

I got your JPEG example demo. But it seems the bitmap loader still have some bug.
Loading a JPEG image is no problem..
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

Hi Onan,

Is it my example which has some bugs or are you mentioning about the BitmapFromResouce function, here is the fixed version.

http://www.masmforum.com/simple/index.php?topic=2743.msg21561#msg21561

Farabi

Quote from: Vortex on September 27, 2005, 05:03:26 PM
Hi Onan,

Is it my example which has some bugs or are you mentioning about the BitmapFromResouce function, here is the fixed version.

http://www.masmforum.com/simple/index.php?topic=2743.msg21561#msg21561

I dont know. But I think it is BitmapFromFile which is have bug.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

Hi Onan,

My JPGdemo.zip example comes with a corrected version of BitmapFromFile Is there any situation where my example doesn't work? ( That example loads a JPG image and displays it in a dialog box. )

Farabi

Your example works fine. Maybe my algo made mistake, but Im sure it is not.
When it executed by RadAsm all is fine, but when I click the icon it is not fine.

This is my load function.

fLoadPicture proc uses esi edi wDC:dword,mDC:dword,x:dword,y:dword,l:dword,t:dword,filename:dword
LOCAL buff[512],hMemDC,hBitmap,mptr:dword

invoke mAlloc,10000
mov mptr,eax
invoke SetBkMode,wDC,OPAQUE

invoke GetCurrentDirectory,2048,mptr
invoke lstrcat,mptr,filename

until_loaded:
invoke BitmapFromFile,mptr
.if eax==0
jmp @f
er db "Loading error(stuck).",0
@@:
invoke PERR
.endif

mov hBitmap,eax
invoke CreateCompatibleDC,wDC
mov hMemDC,eax
invoke SelectObject,eax,hBitmap
invoke BitBlt,mDC,x,y,l,t,hMemDC,0,0,SRCCOPY


invoke DeleteObject,hBitmap
invoke DeleteDC,hMemDC

invoke GlobalFree,mptr


ret
fLoadPicture endp


I attach my software. Tell me if the mask bitmap is not loaded.

[attachment deleted by admin]
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

Hi Onan,

Running your demo, I receive an error mesage saying that the specified file cannot be found.

Farabi

Yes erol. I dont know what causing it. Have you try to load more than one picture? If you can do it, it must be bug from my code.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

Hi Onan,

Your zip file doesn't contain any source code, so it's difficult to talk about the source of the problem.

Erol

Vortex

Hi Onan,

Here are the fixed procedures from Ernest Murphy's image library.

[attachment deleted by admin]

Farabi

Thank you for the fixed lib. It have no error on this laptop. I will test it tomorrow on as many computer as I can.
Quote
Your zip file doesn't contain any source code, so it's difficult to talk about the source of the problem.
Yes. Thank you.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"