LCL/Graphics: Fix handling of color transparency in TRasterImage and descendants. Issue #41726.

This commit is contained in:
wp_xyz 2025-06-30 17:09:25 +02:00
parent 5c34fbf059
commit 1661d5ff48
2 changed files with 20 additions and 6 deletions

View File

@ -1245,6 +1245,7 @@ type
FUpdateCount: Integer;
FUpdateCanvasOnly: Boolean;
FMasked: Boolean;
FTransparentPending: Boolean;
procedure CanvasChanging(Sender: TObject);
procedure CreateCanvas;
@ -1300,6 +1301,7 @@ type
procedure WriteData(Stream: TStream); override;
procedure WriteStream(AStream: TMemoryStream); virtual; abstract;
function RequestTransparentColor: TColor;
procedure ApplyTransparent;
public
constructor Create; override;
destructor Destroy; override;

View File

@ -379,9 +379,7 @@ begin
then FTransparentMode := tmAuto
else FTransparentMode := tmFixed;
if MaskHandleAllocated
then MaskHandle := 0
else Changed(Self);
ApplyTransparent;
end;
procedure TRasterImage.Changed(Sender: TObject);
@ -702,9 +700,14 @@ begin
if AValue = TransparentMode then exit;
FTransparentMode := AValue;
if AValue = tmAuto
if FTransparentColor = clDefault then
FTransparentMode := tmAuto;
if FTransparentMode = tmAuto
then TransparentColor := clDefault
else TransparentColor := RequestTransparentColor;
ApplyTransparent;
end;
procedure TRasterImage.SetTransparent(AValue: Boolean);
@ -714,8 +717,8 @@ begin
lTransparent := GetTransparent();
if AValue = lTransparent then Exit;
// some delphi compatibility, we can only change transparency through the mask.
Masked := AValue;
FTransparentPending := AValue;
ApplyTransparent;
end;
// release handles without freeing them
@ -976,6 +979,15 @@ begin
SetSize(Width, AHeight);
end;
procedure TRasterImage.ApplyTransparent;
begin
if MaskHandleAllocated then
MaskHandle := 0;
// some delphi compatibility, we can only change transparency through the mask.
SetMasked(FTransparentPending);
end;
// included by graphics.pp