[SOLVED] TBitmap with alpha lazarus / 39-Graphics ---------------------------------------------------------------------- mercury · 2015-03-11 13:44 I just want change the color. Code: [Select]var   I, J: integer;   C: TColor;   R, G, B: byte;   Bitmap: TBitmap; begin ......     with Bitmap do begin       for J := 0 to Height - 1 do begin         for I := 0 to Width - 1 do begin           C := Canvas.Pixels[I, J];           R := integer(GetRValue(C)) div 1;           G := integer(GetGValue(C)) div 30;           B := integer(GetBValue(C)) div 30;           Canvas.Pixels[I, J] := TColor(RGB(R, G, B));         end;       end;     end; end; The color is changed, but also lost transparence. And with this : Code: [Select]var   I, J: integer;   C: TColor;   R, G, B: byte;   Bitmap: TBitmap; begin ......     with Bitmap do begin       for J := 0 to Height - 10 do begin         for I := 0 to Width - 10 do begin           C := Canvas.Pixels[I, J];           R := integer(GetRValue(C)) div 1;           G := integer(GetGValue(C)) div 30;           B := integer(GetBValue(C)) div 30;           Canvas.Pixels[I, J] := TColor(RGB(R, G, B));         end;       end;     end; end; The picture just lost the part I changed ( J := 0 to Height - 10  and  I := 0 to Width - 10) It's inconceivability. Anyone can tell me why? And also many function will destroy transparence like: Code: [Select]Bitmap.Width = xxx; Bitmap.Canvas.CopyRect(xxx); How can I keep the transparence? Thank you. ---------------------------------------------------------------------- User137 · 2015-03-11 15:01 You need to switch RGB functions to RGBA ones. TColor contains the transparency in it, so by using RGB you are overriding it with solid alpha. ---------------------------------------------------------------------- mercury · 2015-03-11 15:07 Quote from: User137 on March 11, 2015, 04:01:39 pmYou need to switch RGB functions to RGBA ones. TColor contains the transparency in it, so by using RGB you are overriding it with solid alpha. seems no such a function called RGBA. ---------------------------------------------------------------------- mm7 · 2015-03-11 20:49 TColor does not have translucency (Alpha). TFPColor does. I believe to achieve translucency you need either to use FP API, or to work directly with bitmap memory. Bitmap should be created with RawImage.Description that has AlphaPrec >0, usually 8. Then after RawImage.CreateData you can work with RawImage.Data. In Linux, I've found that any call to Canvas functions will destroy all your previous work with RawImage.Data because the raw data will be rebuilt to native format (your current X11 Server format). This reading may help you http://wiki.freepascal.org/Fast_direct_pixel_access ---------------------------------------------------------------------- VTwin · 2015-05-02 05:39 Have you tried TBGRABitmap? It has alpha and much more. VTwin ---------------------------------------------------------------------- circular · 2015-05-04 11:37 Yes, with BGRABitmap you could do it like that: Code: [Select]var   I, J: integer;   C: TBGRAPixel;   Bitmap: TBitmap; begin ......     with Bitmap do begin       for J := 0 to Height - 1 do begin         for I := 0 to Width - 1 do begin           C := GetPixel(I, J);           C.red := C.red div 1;           C.green := C.green div 30;           C.blue := C.blue div 30;           SetPixel(I,J, C);         end;       end;     end; end; Or do something faster with a PBGRAPixel pointer. See: http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_4