I have a component rendering an image at run-time:
I copy a "screenshot" of the component (with a transparent background) to the clipboard:
procedure CopyHtPanelToClipboard(HtPanel: THtPanel);
// Copy a "screenshot" (with transparent background) of the HtPanelPreview component to the clipboard
var
Bitmap: iexBitmaps.TIEBitmap;
begin
Bitmap := iexBitmaps.TIEBitmap.Create;
try
// Set the size of the bitmap to the size of the THtPanel:
Bitmap.Width := HtPanel.Width;
Bitmap.Height := HtPanel.Height;
// Render the THtPanel onto the bitmap:
HtPanel.PaintTo(Bitmap.Canvas, 0, 0);
// testing the Bitmap at this stage:
Bitmap.Write('C:\DELPHI\MyTest\test.png', ioPNG);
// Get transparent color (transColor is type TRGB)
var transColor := Bitmap.Pixels[0, Bitmap.Height - 1];
Bitmap.SetTransparentColors(transColor, transColor, 0);
// Copy the bitmap to the clipboard:
Bitmap.CopyToClipboard(True, True); // Todo: The image background has artifacts!
finally
Bitmap.Free;
end;
end;
Unfortunately, the clipboard image has artifacts on the background:
How do we avoid the artifacts and show a transparent background?
Testing the Bitmap after HtPanel.PaintTo reveals that the artifacts have already been added at that stage.