Recent Changes - Search:

Support

Site

Links

FAQ /

AlphaTransparency

<< Layers | Frequently asked questions | Image format related >>

1. Is it possible to make the alpha blending to the desktop or other components on the form?

No, this feature is not supported and it is not planned in future. Though, it is in principle possible to get windowed controls blended to the background in Windows 2000, I want to keep the library compatible with previous OS versions and I want to keep it as separate from GDI as possible.

2. How do I load both image and its alpha mask in run-time?

The problem is that there is no widely available software (at least known to me) normally supporting saving of images with alpha channel, (that should be in principle possible with TGA, TIFF, PNG and some other formats). So either create your own file loading procedure (you have access to the bitmap's memory, so that should not be a big problem), or use the sample shown below to load RGB and Alpha channels from different bitmaps (they must be of the same size):

var
  RGBBitmap: TBitmap32;
  AlphaBitmap: TBitmap32; // source for alpha channel
begin
  RGBBitmap.LoadFromFile(RGB_Channels);
  AlphaBitmap.LoadFromFile(Alpha_Channel); //grayscale (or maybe colored mask)
  IntensityToAlpha(RGBBitmap, AlphaBitmap);
end;

3. How do I draw the bitmap with standard color key transparency?

Currently Graphics32 does not support color key transparency, but it is possible to preprocess the source bitmap and set its alpha buffer according to the "transparent" color:

procedure ChromaKey(ABitmap: TBitmap32; TrColor: TColor32);    // former CromaKey <v1.8.3
var
  P: PColor32;
  C: TColor32;
  I: Integer;
begin
  TrColor := TrColor and $00FFFFFF; // erase alpha, (just in case it has some)
  with ABitmap do
  begin
    P := PixelPtr[0, 0];
    for I := 0 to Width * Height - 1 do
    begin
      C := P^ and $00FFFFFF; // get RGB without alpha
      if C = TrColor then // is this pixel "transparent"?
        P^ := C; // write RGB with "transparent" alpha back into the SrcBitmap
      Inc(P); // proceed to the next pixel
    end;
  end;
end;

Then, set the DrawMode to dmBlend and call Draw or DrawTo? to blend it to a background bitmap. It is possible to use this function several times for different colors. As of Graphics32 version 1.7 this procedure is included in the unit GR32_Filters.

Edit - History - Print - Recent Changes - Search
Page last modified on May 17, 2009, at 04:38 PM