News:

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

Some Bitmap/Image Questions

Started by Rainstorm, December 16, 2008, 08:58:41 AM

Previous topic - Next topic

Rainstorm

Hi.

- the CreateBitmap Function asks for various values - where can i get these values from ? - usually there is a function that fills a structure or something with these values, but i can't find it. - in what situations is CreateBitmap used ?

- A Lot of the documention seems to describe Bitmap usage as a resource, or loading resources from .exe files, not from disk. - LoadImage is the only one i found that can load from disk.

same with CreateBitmapIndirect, etc where do i get the info from to fill the structure with.

many thanks.

Rainstorm
-

Vortex

Hi Rainstorm,

Raymond coded a nice library to load images :

http://www.masm32.com/board/index.php?topic=9538.0

http://www.masm32.com/board/index.php?topic=4266.0

You can use the BitmapFromFile function from masm32.lib to load images from disc :

QuoteBitmapFromFile proc pszFileName:DWORD

Description

BitmapFromFile returns a bitmap handle from an image file.
An image may be in either .bmp, .gif, .jpg, or .wmf format


Parameters

1. pszFileName pointer to the pathname of an image file


Return Value

The return value is a handle to a bitmap representation of the file compatible with the screen device context. If the function fails, the return value is NULL. To get extended error information, call GetLastError.


Comments

This function is provided as a convenience to the MASM32 community. It is not composed of highly optimized assembly code, so do not expect blinding speed.

This function uses certain aspects of the Windows API to do the actual conversion from the particular image format. Since the function contains no proprietary code, it may be used without any royalty payments. This may be especially important to those wishing to use .gif files.

Rainstorm

Vortex thanks,  :U that would do just fine.
I had a quick look at the code of the procs, ..... not what i had imagined & quite a surprise  :lol - seems to be COM related (i think).

laters

Vortex

Hi Rainstorm,

Here is a sample loading a bitmap from disc. The CreateBmpFromMem function uses the CreateDIBitmap API. The code has no any reference to COM.


.IF uMsg==WM_CREATE

        invoke  CreateFile,ADDR FileName,GENERIC_READ,\
                0,0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0
        mov     hFile,eax
        invoke  GetFileSize,eax,0
        mov     FileSize,eax
        invoke  VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
        mov     pMem,eax
        lea     ecx,bBytes
        invoke  ReadFile,hFile,eax,FileSize,ecx,0
        invoke  CloseHandle,hFile     
                       
        invoke  CreateBmpFromMem,hWnd,pMem
        mov     hBitmap,eax




[attachment deleted by admin]

Vortex

Another example with CreateDIBSection :


.IF uMsg==WM_CREATE

        .
        .
        .
        mov     eax,pMem
        add     eax,sizeof(BITMAPFILEHEADER)    ; start of BITMAPINFOHEADER header
        invoke  CreateDIBSection,0,eax,DIB_RGB_COLORS,ADDR ppvBits,0,0
        mov     hBitmap,eax
        mov     eax,pMem
        add     eax,sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
        mov     ecx,FileSize
        sub     ecx,sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
        invoke  MemCopy,eax,ppvBits,ecx         ; copy bitmap's bit values         



[attachment deleted by admin]

Rainstorm

Vortex, thankies !. . . I could relate to these examples much more easily. - I've got an idea how its done now :U