Use this image:
attach/PeterPanino/2024611173948_NewTestImage.zip
950 Bytes
procedure TForm1.MakeTransparentByLightness(ImageEnView: TImageEnView; Threshold: Integer);
var
x, y: Integer;
IEBitmap: TIEBitmap;
AlphaBitmap: TIEBitmap;
PixelColor: TRGB;
Lightness: Integer;
AlphaScanLine: PByteArray;
begin
IEBitmap := ImageEnView.IEBitmap; // Reference to the ImageEnView bitmap
// Ensure the bitmap has an alpha channel
if not IEBitmap.HasAlphaChannel then
IEBitmap.AlphaChannel;
AlphaBitmap := IEBitmap.AlphaChannel; // Reference the alpha channel bitmap
// Process each pixel to make those below or above the threshold transparent
for y := 0 to IEBitmap.Height - 1 do
begin
AlphaScanLine := AlphaBitmap.ScanLine[y];
for x := 0 to IEBitmap.Width - 1 do
begin
// Access the pixel color as TRGB
PixelColor := IEBitmap.Pixels_ie24RGB[x, y];
// Calculate the Lightness value
Lightness := PARGBToIntL(PixelColor);
if Lightness < Threshold then
AlphaScanLine[x] := 0 // Make pixel fully transparent
else
AlphaScanLine[x] := 255; // Make pixel fully opaque
end;
end;
// Ensure the alpha channel is in sync
IEBitmap.SyncAlphaChannel;
// Force the component to redraw:
ImageEnView.Update; // Does NOT update the image!!
end;
procedure TForm1.ButtonLimitImageColorsClick(Sender: TObject);
begin
MakeTransparentByLightness(ImageEnView1, 300);
end;
function TForm1.PARGBToIntL(ARGB: TRGB): Integer;
// converts TRGB to Integer Luminance value
var
H, S, L: Double;
begin
hyieutils.RGB2HSL(ARGB, H, S, L);
Result := Round(L * 1000);
end;
Why does ImageEnView.Update; not update the image??