1. Win32 Transparency
- Posted by David Cuny <dcuny at LANSET.COM> May 05, 1999
- 321 views
Does anyone know if there is a relatively easy way to display "transparent" images in using the Win32 API? I've run across the 'image list' where you store a bitmap and a mask, but it looks a bit klunky. In specific, I want to display bitmaps (such as a checkbox or radio button) in a window. One color ({255,0,255} in particular) is designated as "transparent", and should not be rendered. In theory, I could blit the destination pixels, manally blend it with the bitmap, and blit it back, but I was looking for something built into the Win32 API. It looks like perhaps the animation control could be used for this purpose... Any suggestions? Thanks. -- David Cuny
2. Re: Win32 Transparency
- Posted by Greg Harris <blackdog at CDC.NET> May 05, 1999
- 317 views
- Last edited May 06, 1999
Hi David, -----Original Message----- From: David Cuny <dcuny at LANSET.COM> Subject: Win32 Transparency >Does anyone know if there is a relatively easy way to display "transparent" >images in using the Win32 API? I've run across the 'image list' where you >store a bitmap and a mask, but it looks a bit klunky. No there isn't a relative easy way to do this in the Win32 API that I know of. I've used the above method with fair success. Reagrds, Greg Harris
3. Re: Win32 Transparency
- Posted by Nuno Barros <nuno.barros at IP.PT> May 06, 1999
- 338 views
Greg Harris wrote: > Hi David, > > -----Original Message----- > From: David Cuny <dcuny at LANSET.COM> > Subject: Win32 Transparency > > >Does anyone know if there is a relatively easy way to display "transparent" > >images in using the Win32 API? I've run across the 'image list' where you > >store a bitmap and a mask, but it looks a bit klunky. > > No there isn't a relative easy way to do this in the Win32 API that I know > of. > I've used the above method with fair success. > > Reagrds, > > Greg Harris of course there is... with gdi32.dll you can do all these stuff with masks.... You have to create first two CompatibleBitmaps (one for hold your source bitpmaps and another to serve as stage where the screen is assembled and the called to screen). I have somewhere docs about the tecnique... I will find them... For now stay with a sample of a program done in Lyberty Basic... it could be easily trnslated for Euphoria... I hope it helps anyway.. calldll #user ,"GetDC",_ hG as word,_ 'the handle of the graphic box hDC as word 'the handle of the DC of the graphic box calldll #gdi,"CreateCompatibleDC",_ hDC as word,_ 'the handle of the DC of the graphic box hdcMEM as word 'the handle of the new DC we create calldll #gdi,"CreateCompatibleDC",_ hDC as word,_ 'the handle of the DC of the graphic box hdcSTAGE as word 'the handle of the DC we create calldll #gdi,"CreateCompatibleBitmap",_ hDC as word,_ 'the handle of the DC of the graphic box 352 as word,_ 'width of new bitmap in memory 352 as word,_ 'height of new bitmap in memory stage as word 'name we give our new bitmap in memory calldll #gdi,"SelectObject",_ hdcSTAGE as word,_ 'DC in memory to hold bitmaps stage as word,_ 'the name of the bitmap we place in this DC result as word calldll #gdi,"SelectObject",_ hdcMEM as word,_ 'DC in memory to hold bitmaps hback as word,_ 'the name of the bitmap we place in this DC r as word [put.in.screen] calldll #gdi,"BitBlt",_ hDC as word,_ 0 as word,_ 0 as word,_ 352 as word, _ 352 as word,_ hdcSTAGE as word, _ 0 as word, _ 0 as word,_ 13369376 as long, _ r as ushort 'print #1.g, "getbmp bmpname 0 0 352 352" 'print #1.g, "drawbmp bmpname 0 0" 'print #1.g, "flush" return [drawinstage] calldll #gdi,"SelectObject",_ hdcMEM as word,_ 'DC in memory to hold bitmaps hback as word,_ 'the name of the bitmap we place in this DC r as word calldll #gdi,"BitBlt",_ hdcSTAGE as word,_ 'destination DC - copy image to here xto as word,_ 'x location to place image yto as word,_ 'y location to place image width as word, _ 'width of image to transfer height as word,_ 'height of image to transfer hdcMEM as word, _ 'source DC - copy image from here xfrom as word, _ 'x location to copy from yfrom as word, _ 'y location to copy from 13369376 as long, _ 'SRCCOPY r as ushort return [add.mask] calldll #gdi,"SelectObject",_ hdcMEM as word,_ 'DC of memory hmask as word,_ 'name of mask image r as word calldll #gdi,"BitBlt",_ hdcSTAGE as word,_ 'destination DC = memory staging area xto as word,_ 'x location to place image yto as word,_ 'y location to place image width as word, _ 'width of image to transfer height as word,_ 'height of image to transfer hdcMEM as word, _ 'source DC = memory xfrom as word, _ 'x location to copy image from yfrom as word, _ 'y location to copy image from 8913094 as long, _ 'SRCAND r as ushort return [add.sprite] calldll #gdi,"SelectObject",_ hdcMEM as word,_ 'DC of memory hobj as word,_ 'name of normal image r as word calldll #gdi,"BitBlt",_ hdcSTAGE as word,_ 'destination DC = memory staging area xto as word,_ 'x location to place image yto as word,_ 'y location to place image width as word, _ 'width of image to transfer height as word,_ 'height of image to transfer hdcMEM as word, _ 'source DC = memory xfrom as word, _ 'x location to copy image from yfrom as word, _ 'y location to copy image from 15597702 as long,_ 'SRCPAINT r as ushort return and now a piece of code to call that funtions.... it would print on screen a masked bitmap with 32x32 pixels x=2 y=9 xto=32*(x-1) yto=32*(y-1) xfrom=160 yfrom=224 widht=32 height=32 gosub [add.mask] gosub [add.sprite] gosub [put.in.screen] -- N u n o B a r r o s [ W e b D e s i g n e r ] ---------------------------------------------------------------------- [ m a i l ] nuno.barros at ip.pt [ i c q ] 6 4 4 8 3 8 8 ---------------------------------------------------------------------- Webdesign Portfolio http://nuno.homepage.nu e . t o p i a -in construction- http://etopia.homepage.nu C h a o s S q u a d http://gollop.homepage.nu L i m b o http://limbo.homepage.nu ----------------------------------------------------------------------
4. Re: Win32 Transparency
- Posted by Greg Harris <blackdog at CDC.NET> May 06, 1999
- 332 views
On Thu, 6 May 1999 10:54:05 +0200, Nuno Barros <nuno.barros at IP.PT> wrote: >Greg Harris wrote: >>>Does anyone know if there is a relatively easy way to display >>>"transparent" >>>images in using the Win32 API? I've run across the 'image list' where you >>>store a bitmap and a mask, but it looks a bit klunky. > >>No there isn't a relative easy way to do this in the Win32 API that I know >> of. I've used the above method with fair success. >of course there is... with gdi32.dll you can do all these stuff with masks.... -snip- Actually, I should have been more clear. I was referring to the method that you described. I was under the impression that David was looking for a more simpler approach to transparency than having to go through 3 BitBlts and the ilk. There is an option that *some* video cards have to support transparency coding with direct BitBlit support. However (as of the time of writting of the article that I found on MSDN (circa 1994)) not all video cards supported this driver feature. Supposedly you could detect it with GetDeviceCaps. Other than this method or DirectX.. it appears (IMHO) to be quite a kludge to do transparency in Windows. Your example was quite well presented. Regards, Greg Harris