Copy Rectangle with Transparency
Original Reporter info from Mantis: Blaazen @Blaazen
-
Reporter name: Vojtech Cihak
Original Reporter info from Mantis: Blaazen @Blaazen
- Reporter name: Vojtech Cihak
Description:
Now, only Canvas.Draw(x, y, TBitmap); can draw with transparency.
Canvas.CopyRect(Dest: TRect; SrcCanvas: TCanvas; Source: TRect); ignores transparency.
I would like to have faster CopyRect with transparency (copy 1:1, no stretch needed).
This is working example:
procedure CopyRectTrans(const Dest: TRect; SrcBMP: TBitmap; const Source: TRect);
var i, j: Integer;
aColor, trColor: TColor;
begin
trColor:=SrcBMP.TransparentColor;
for j:=Source.Top to Source.Bottom-1 do
for i:=Source.Left to Source.Right-1 do
begin
aColor:=SrcBMP.Canvas.Pixels[i, j];
if aColor<>trColor then Canvas.Pixels[Dest.Left-Source.Left+i, Dest.Top-Source.Top+j]:=aColor;
end;
end;
but it is 5-10 times slower than CopyRect. IMO t is because of accessing to Pixels[x, y] which is AFAIK very slow.
I appreciate faster implementation.
Thanks.
Mantis conversion info:
- Mantis ID: 20234
- Version: 0.9.31 (SVN)
- Monitored by: » etrusco (Flávio Etrusco)
- Target version: 1.4