I needed to set all Transparent Pixels in a TImageEnView image to a specific Opaque Color:
procedure SetAllTransparentPixelsToOpaqueColor(ImageEnView: imageenview.TImageEnView; AColor: Vcl.Graphics.TColor);
// Set all Transparent Pixels in TImageEnView to a specific Opaque Color
var
x, y: Integer;
ThisBitmap: iexBitmaps.TIEBitmap;
RGBColor: hyiedefs.TRGB;
begin
ThisBitmap := ImageEnView.IEBitmap;
// Optimize performance by locking updates:
ImageEnView.LockUpdate;
try
// Define the RGB color:
RGBColor := hyieutils.TColor2TRGB(AColor);
for y := 0 to ThisBitmap.Height - 1 do
begin
for x := 0 to ThisBitmap.Width - 1 do
begin
if ThisBitmap.Alpha[x, y] < 255 then // if the pixel is not fully opaque
begin
// Set the pixel color to the new color and make it fully opaque:
ThisBitmap.Pixels[x, y] := RGBColor;
ThisBitmap.Alpha[x, y] := 255; // Set pixel alpha to fully opaque
end;
end;
end;
finally
// Ensure updates are unlocked even if an exception occurs:
ImageEnView.UnlockUpdate;
ImageEnView.Update;
end;
end;
Is there a better built-in replacement for this task in ImageEn?