Hi guys,

I have implemented an image (gif), and now i want to set the background of it to TRANSPARENT. But I dont know how.

Couldnt find anything at this board.


DKT
Posted on 2003-11-02 08:21:02 by Kreatief
If you could not find anything on this board about transparency then something is seriously wrong with you :eek:

You need to use a 24 or 32 bit image (since 24 is really using 32 as well) and set the Alpha component of pixel color data ...
I recommend using the board's SEARCH facility !!
:stupid:
Posted on 2003-11-04 23:29:03 by Homer
You need to use 32 bit to use alpha blending, 24 bit has no allowance for an alpha channel. But if you are just looking for a simple tranparency you have no need for alpha blending, you can just draw it with a mask. Draw the mask onto the DC with a transparent background mode then use SRCAND to blit the bitmap to the DC. All pixels corresponding to white pixels on the mask will be painted, those corresponding to black will not. Alpha blending is used for partial transparencies and is a rather complicated thing to implement unless you do not plan to modify the image.

If your goal is to make the background partially visible through the image you use alphablends, there are essentially two types of alpha blending available to Windows. The first is a global alpha that will blend all pixels at the same level of transparency the second is source alpha that will blend each pixel dependant on the value of it's alpha channel. If you wish to use global alpha blends the alpha channel (bits 24-32) must be set to zero and use the following:

bf BLENDFUNCTION <AC_SRC_OVER,0,255,NULL> ; 255 is the level of transp. 0 = fully transp 255 = opaque

mov eax,OFFSET bf
mov eax,[eax]
mov BlendFunction,eax
invoke AlphaBlend,hDC,0,0,rct.right,rct.bottom,hMemDC,0,0,imageX,imageY,BlendFunction


For per pixel blending the source alpha must be set to 255 i.e.

bf BLENDFUNCTION <AC_SRC_OVER,0,255,AC_SRC_ALPHA>

mov eax,OFFSET bf
mov eax,[eax]
mov BlendFunction,eax
invoke AlphaBlend,hDC,0,0,rct.right,rct.bottom,hMemDC,0,0,imageX,imageY,BlendFunction


The AlphaBlend function requires that the bitmap be premultiplied in order to properly blend it is you are using source alpha (per pixel) you can get a good algorithm for this from the sniplett by Bitrake on the MadWizards page

http://www.madwizard.org/view.php?page=snippets&PHPSESSID=7a9f71218080b46876e5de7e0abb425c
Posted on 2003-11-05 00:05:28 by donkey
I am so sorry, i just reread my post, and came to the conclusion, that it was nonsense. What i meant is:

I have a transparent gif file. Now, i want to implement it in my program. But if I put it somewhere, the transparent parts arent transparent but black. How to turn this into transparany?


Sorry for my first post... :(



DKT
Posted on 2003-11-05 13:31:22 by Kreatief
have you read donkey's post ???

I will make some short version for you + my something from my own .

Gif is such a format that you can pick color to act as a transparent. In your case it was black but it can be different. Gif is not visible by windows (if i can say it like that) but you can convert it into bitmap format to use it. Since bitmaps got no transparency your transparency color will appear on your image. So you have to make mask containing part of youre image with transparency. When you want to paint it somewhere you are painting it using a mask. For "BitBlt" API you can use SRCAND. Of course This Api is working with Device Context so you have to make DC and SelectObject ---> (bitamp) into it.
Posted on 2003-11-05 15:06:28 by AceEmbler
Hi
Since I'm not sure of what is it exactly what you need to do, I'll try to cover everything :grin: :

There are many ways to do transparency. The ones listed in this thread are used with bitmaps, wich is the format that GDI (the standard library for GUI under Windows) supports. There is one more: you can use region objects (search the board!).

If you are using masm32.lib to load the GIF, then you are actually converting it to a bitmap. So all of the above applies.

Since you mentioned GIF files, I suppose you are actually using OLE to load a gif picture (rather than GDI). If the file already has a color set for transparency, then the Render method of the IPicture interface will only draw the pixels that are not transparent, leaving the rest untouched, so all you have to do is render the GIF picture AFTER you painted the background.

If what you want is to use the gif as a "skin" for your app, you must create a region and use it with your window - that way Windows will know wich pixels "belong" to your app, and wich ones to the windows beneath yours.

Naturally, if the gif picture has no color set as transparent, there will be no transparency (duh! :grin: ). There are numerous GIF editors out there to do that.

Now, if you want to load a GIF picture and CHANGE it's transparent color, I'm not sure but probably there's a method for it too. ;)

In any of this cases, I'm pretty sure that there are some examples in the board.
Posted on 2003-11-05 17:24:21 by QvasiModo
Hi,

thank you for your posts. I solved it, but in another way, than it should be. I jus painted the "transparent" part with the color of the normal grey dialog boxes. Now it looks transparent, but isnt :)

It seems to be harder than i thought... I thought about a function like transparency for text bcakgrounds or something. But anyway, i solved it in a way that is acceptable.


Wish you a nice day...

DKT
Posted on 2003-11-06 09:07:32 by Kreatief