PDA

View Full Version : Make semi-transparent images



neafriem
24-03-2005, 10:45 AM
I use the following code to draw an image:


Image1.Transparent := True;
Bufferbox.Canvas.Draw(0, 0, Image1.Picture.Bitmap);

The background color, that will became invisible, is purple.
My question is this: Think if you have a torch then you want the flames have like 50% opacity so you can see through them. But when I paint the torch and it's flames with a yellow color with the 50% opacity the image looks fine until I run the program because then the torch will have purple flames!
I hope I have explained this propely, if not askwhat the hell I meen! :P

Sly
24-03-2005, 11:00 AM
The process you describe is called alpha-blending, and the standard TCanvas.Draw method does not support any kind of alpha blending.

A couple of solutions for you.
- Use one of the libraries that give you 2D graphics using the 3D capabilities of your video card via Direct3D or OpenGL. Such libraries include Asphyre, GameVision and Omega.
- Use GDI+. It is used by Windows XP to draw the fading menus, to name one example.
- Libraries such as GraphicsEx or GSoft that provide alpha-blending functionality.

WILL
24-03-2005, 10:17 PM
If you plan on using a major API for your graphics, you can look at using the alpha channel (some libraries or component suites support it others don't). In some graphics modes you have RGBA or ARGB, etc... this will take that 4th byte(in a 32bit color mode) of video data and use it to do the alpha blending on that pixel. Could this be what you are sugesting aswell? Keep in mind that this is relatively harder to produce since your sprite or torch image will be seen and possibly only stored in RGB format.