Computer Science Canada How do I colour key in gdi32? |
Author: | CodeMonkey2000 [ Sat Oct 20, 2007 12:20 pm ] |
Post subject: | How do I colour key in gdi32? |
I don't know what this is called in VB, what I want is to set transparent colours, so when I blit the image, the white pixels get ignored. |
Author: | Nick [ Sat Oct 20, 2007 4:16 pm ] |
Post subject: | RE:How do I colour key in gdi32? |
u mean similair's to turing's picMerge? |
Author: | Euphoracle [ Sat Oct 20, 2007 5:17 pm ] |
Post subject: | RE:How do I colour key in gdi32? |
No, he means set a transparency key so any pixel of that color is not drawn. PicMerge is just a method of drawing it, whereas it simply leaves the empty pixels as they were before drawing the image, thus giving you the "transparent" effect. |
Author: | CodeMonkey2000 [ Sun Oct 21, 2007 3:26 pm ] |
Post subject: | RE:How do I colour key in gdi32? |
Well I found something on Microsoft's site that might help, you have to use vbMergeCopy. But the problem is I don't know how to use it. EDIT: I found another function, it's called transparentblt. It's a wee bit slow though. Is there an alternative? |
Author: | Brightguy [ Mon Oct 22, 2007 2:13 am ] | ||
Post subject: | Re: How do I colour key in gdi32? | ||
Yeah, there's TransparentBlt (which apparently has a memory leak on Win98) or you can do it with two calls to BitBlt. First, prepare a copy of your image with black pixels everywhere you want transparency. Then, prepare the "mask": your image with white pixels everywhere you want transparency and black pixels where you don't. You can use these images to create transparency as follows: First, blit the mask onto the background using the raster operation AND (a bitwise AND on the pixel values). The white areas are 1 in binary so they don't change (x AND 1 = x), while the black areas are 0s in binary so are set to 0 (x AND 0 = 0). Thus, you end up with a black "hole" in the background in the shape of your image. Then, blit the first image onto the background using the raster operation OR (a bitwise OR on the pixel values). The black areas are 0 in binary so they don't change (x OR 0 = x), so you can blit your image onto the black hole without changing anything, and without changing any pixels outside of the hole. If want to be really 1337, you can automate the process of creating the mask, given an image and a background colour. I've updated my "double buffering" example program to do this. To try it, just change the filename and picBackground constants as appropriate (I'll attach an example image with this post). I've also made it so you can change the displayed background colour.
|
Author: | bellopapo [ Mon Mar 09, 2009 5:22 am ] |
Post subject: | Re: How do I colour key in gdi32? |
hi i tried the example ... it's ok but image has a lot of "gosts", that are the old images when doggie2.gif go in another location. so .. is it possible to display on screen ONLY ONE doggie2.gif after it is moved ? many thanks peppe |
Author: | Brightguy [ Wed Mar 11, 2009 10:33 pm ] | ||
Post subject: | Re: How do I colour key in gdi32? | ||
Sure, you just want to clear the background before each new doggie is drawn. Add something like...
...right before "Draw picture on background" in Form_MouseMove. And I just realized ExtFloodFill is really slow (that's "onboard graphics accelerator" for you). If you don't care about the background colour you can remove that. |