// Bitmap transparent darstellen unter FireMonkey.

// Getestet mit RS 10.4 unter Win10
 
uses System.UIConsts; 
 
procedure MakeTransparent(Bitmap: TBitmap; 
  TransparentColor: TAlphaColor); overload; 
var 
  data: TBitmapData; 
  i, j: Integer; 
begin 
  Bitmap.Map(TMapAccess.ReadWrite, data); 
  for i := 0 to pred(data.width) do 
  begin 
    for j := 0 to pred(data.Height) do 
    begin 
      if (data.GetPixel(i, j) = TransparentColor) then 
        data.SetPixel(i, j, 0); 
    end; 
  end; 
  Bitmap.Unmap(data); 
end; 
 
procedure MakeTransparent(Bitmap: TBitmap; x, y: Integer); 
overload 
var 
  data: TBitmapData; 
  i, j: Integer; 
  TransparentColor: TAlphaColor; 
begin 
  Bitmap.Map(TMapAccess.ReadWrite, data); 
  TransparentColor := data.GetPixel(x, y); 
  for i := 0 to pred(data.width) do 
  begin 
    for j := 0 to pred(data.Height) do 
    begin 
      if (data.GetPixel(i, j) = TransparentColor) then 
        data.SetPixel(i, j, 0); 
    end; 
  end; 
  Bitmap.Unmap(data); 
end; 
 

// Beispielaufruf 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  MakeTransparent(Image1.Bitmap, claWhite); 
  MakeTransparent(Image2.Bitmap, 0, 0); 
end;
 

 

Zugriffe seit 6.9.2001 auf Delphi-Ecke