why does not work the change of alpha value in this simple example= lazarus / 39-Graphics ---------------------------------------------------------------------- dcelso · 2012-10-05 10:47 .pas Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,   StdCtrls, LCLIntf, LCLType,IntfGraphics; type   { TForm1 }   TForm1 = class(TForm)     Image1: TImage;     Label1: TLabel;     procedure FormShow(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure toTransparent(var Bitmap: TBItmap; color: RGBQUAD); var   i : integer;   ppixel : PByte; begin // Bitmap.BeginUpdate();  i:=0;  ppixel := Bitmap.RawImage.Data;  while  i <= (Bitmap.Width * Bitmap.Height)  do  begin    ppixel[i+3]:=255;    //  Si es el color pasado por parámetro no se verá    if (ppixel[i]=color.rgbRed) and (ppixel[i+1]=color.rgbGreen) and (ppixel[i+2] = color.rgbBlue)  then    begin     ppixel[i+3]:=0;    end;    Inc(i,4);  end;  //Bitmap.EndUpdate(); end; procedure toTransparentLaz(var Bitmap: TBItmap; color: RGBQUAD); var   lazBitmap: TLazIntfImage;   ImgHandle,ImgMaskHandle: HBitmap;   k, j :integer;   ppixel : PRGBAQuad; begin  lazBitmap:=TLazIntfImage.Create(0,0);  lazBitmap.LoadFromBitmap(Bitmap.Handle,Bitmap.MaskHandle);  for k := 0 to Bitmap.height - 1 do  begin    ppixel := lazBitmap.GetDataLineStart(k);    for j := 0 to Bitmap.width - 1 do    begin      ppixel[j].Alpha := 255;      // Si es negro puro no se verá      if (ppixel[j].Red=color.rgbRed) and (ppixel[j].Green=color.rgbGreen) and (ppixel[j].Blue = color.rgbBlue)  then      begin        ppixel[j].Alpha := 0;      end;    end;  end; end; procedure TForm1.FormShow(Sender: TObject); var   bmp : TBitmap;   v_rgb : RGBQUAD; begin   bmp:= TBitmap.Create;   bmp.PixelFormat:=pf32bit;   bmp.SetSize(150,150);   bmp.Canvas.Brush.Color:= clGreen;   bmp.Canvas.FillRect(20,20,130,130);   bmp.Canvas.Brush.Color:= clYellow;   bmp.Canvas.FillRect(50,50,100,100);   v_rgb.rgbRed:=0;   v_rgb.rgbGreen:=255;   v_rgb.rgbBlue:=255;   toTransparentlaz(bmp,v_rgb);   // toTransparent(bmp,v_rgb);  <--- This one alternative does not work, too.   Image1.Picture.assign(bmp);   Label1.Caption:=IntToStr(PIXELFORMAT_BPP[Image1.Picture.Bitmap.Pixel Format]);   bmp.Free; end; end. .lfm Code: [Select]object Form1: TForm1   Left = 290   Height = 207   Top = 168   Width = 222   Caption = 'Form1'   ClientHeight = 207   ClientWidth = 222   Color = clRed   OnShow = FormShow   LCLVersion = '1.1'   object Image1: TImage     Left = 0     Height = 207     Top = 0     Width = 222     Align = alClient     Transparent = True   end   object Label1: TLabel     Left = 30     Height = 15     Top = 160     Width = 6     Caption = '0'     ParentColor = False   end end ---------------------------------------------------------------------- HomePlaneR · 2012-10-10 15:09 Firstly, the order of the color components stored in RawImage.Data is not RGBA but BGRA. Secondly, TBitmap.BeginUpdate and TBitmap.EndUpdate must be used in order to change the bitmap content by accessing to RawImage.Data after operated with the canvas (you have commented these function calls). Finally, if all the pixels have alpha=0 then the bitmap will not be completely transparent (the alpha channel will be ignored in this case). I mean you should provide different aplha values to have the correct output.