flat assembler
Message board for the users of flat assembler.

Index > Windows > Drawing Transparent Bitmaps

Author
Thread Post new topic Reply to topic
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
sorry if this is in the wrong forum it fits into ASM and Higher level languages so i wasnt 100% sure where it shud go. in my application i draw a picture of a gear, unfortunatly because bitmaps are infact square the background of the picture does not match the background of the window. Ive been using the www.winprog.org which however written C up till now the code has been fairly easy to port over to ASM, however to make the background of the image i need to make a mask then overlap and stuff .etc .etc however im rly havin trouble porting the code below, if ne body could help me port this code or show me an example of an image being drawn on a window or dialog and having the background color transparent:

Code:
HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent)
{
    HDC hdcMem, hdcMem2;
    HBITMAP hbmMask;
    BITMAP bm;

    // Create monochrome (1 bit) mask bitmap.  

    GetObject(hbmColour, sizeof(BITMAP), &bm);
    hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);

    // Get some HDCs that are compatible with the display driver

    hdcMem = CreateCompatibleDC(0);
    hdcMem2 = CreateCompatibleDC(0);

    SelectBitmap(hdcMem, hbmColour);
    SelectBitmap(hdcMem2, hbmMask);

    // Set the background colour of the colour image to the colour
    // you want to be transparent.
    SetBkColor(hdcMem, crTransparent);

    // Copy the bits from the colour image to the B+W mask... everything
    // with the background colour ends up white while everythig else ends up
    // black...Just what we wanted.

    BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

    // Take our new mask and use it to turn the transparent colour in our
    // original colour image to black so the transparency effect will
    // work right.
    BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0,SRCINVERT);
    DeleteDC(hdcMem);
    DeleteDC(hdcMem2);

    return hbmMask;
}


    
Post 07 Jan 2006, 12:59
View user's profile Send private message MSN Messenger Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
http://www.winprog.org/tutorial/transparency.html
try taht site it's in C but C isn't that hard to convert to ASM
Post 07 Jan 2006, 13:36
View user's profile Send private message Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
yer thas what i want help with. ive ported it to this so far though:

Code:
proc CreateBitmapMask,hbmColour,crTransparent
    invoke GetObject,hbmColour,38h,bmp1H
    invoke CreateBitmap,49, 48,1,1, NULL
    mov    [hbmMask],eax
    invoke CreateCompatibleDC,dcMemH
    invoke CreateCompatibleDC,dcMem2H
    invoke SelectBitmap,dcMemH,hbmColour
    invoke SelectBitmap,dcMem2H,hbmMask
    invoke SetBkColor,dcMemH,00000000h
    invoke BitBlt,dcMem2H, 0, 0, 49, 44, dcMemH, 0, 0, SRCCOPY
    invoke BitBlt,dcMemH, 0, 0, 49, 44, dcMem2H, 0, 0,SRCINVERT
    invoke DeleteDC,dcMemH
    invoke DeleteDC,dcMem2H
    mov    eax,hbmMask
    ret
endp 
    


fasm goes no a lot about invalid oprand sizes and values. i think im almost there though i think it dus need some tweaks. im still workin on this so if u can see ne thin wrong with the code let me know!
Post 07 Jan 2006, 13:58
View user's profile Send private message MSN Messenger Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
ive got it to kind of work thou the picture displayed is "chalky" and not like the 32bit picture i embedded in the program it seems to be displayed as something like a 256color picture. heres the package so u can see for ure self. Im absolutely baffled and ive been doin this all day. hopefully somewhere in ure pool (in my case a puddle) of knowledge u know how to do this properly. any help appreciated.

the invertedpic.bmp file is the inverted picture, its inverted bcus basically it dusnt work otherwise Crying or Very sad. the watitshudbe.bmp is the picture of wat it looked like before i inverted it (i didnt lose quality by inverting it, i can invert invertedpic again and it comes out how it shud be).

PS:the password is "password", if u get it right the dialog disappears if u dont u get a message telling u so. not relavent but just added this ne way.


Description:
Download
Filename: project.zip
Filesize: 13.79 KB
Downloaded: 121 Time(s)

Post 07 Jan 2006, 18:28
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.