This is an example of a quick transparency code

andreww
02-03-2002, 12:51 AM
I was trying to work out how to do an easy way of transparency instead of using all that code from the bitblt which was a page long...so i made my own in like 3-4 lines

its attached

ChiefRedBull
02-03-2002, 10:20 AM
A good idea. Nicely done. :)

But what if I'm using a large image... it might take a while....

Garrett Sever
02-03-2002, 11:42 AM
That's exactly the problem with what young andrew has done here.

The Point/PSet (or GetPixel/SetPixel for API) method has been around for quite some time, but it IS hideously slow for larger bitmaps. Try something 300x300 and watch it lag.


The easiest way of accomplishing transparency AND speed is to use two bitmaps for the mask and the picture. I generally use this one. You end up with bigger resource files, but... it'll work 99.99999% of the time.
Another way (and the most complicated) would be to create a monochrome bitmap, use GetBitmapBits to get the individual Bytes of your image. As you loop thru the bits in your pixel array, you create another array of the monochrome bits. You then set the mask pixels by using SetBitmapBits. This puts you in exactly the same place as the first bullet.
Finally would be to use the BitBlt methods to create a mask from the image by setting the back color = transparency color and blting it onto a monochrome bitmap. Unfortunately this doesn't work really well on 95 systems (98 and ME seemed to work well).

Computer_Guy
02-08-2002, 01:33 PM
but, if you use two bitmaps instead, why don't you make the mask into a gif file, so that it is much smaller in file size, won't that decrease resources used? I was also thinking that since I am making an RPG, but there is only one hero, then could I make a gif image, that is already a mask for the tileset of the character, so that I don't have to use Get/Set pixel?
Thanks
Ed

AcidBoot
02-08-2002, 06:41 PM
I tried that a few days ago. For some reason bitblt copied across the transparent pixles as well, eliminating the background.

Check out my solution here http://visualbasicforum.com/showthread.php?s=4fb76e54a23ca32da6a4a1ea6712c0&threadid

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum