ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Render a component screenshot with transparent background?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

901 Posts

Posted - Dec 19 2023 :  02:22:43  Show Profile  Reply
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.

PeterPanino

901 Posts

Posted - Dec 19 2023 :  05:21:37  Show Profile  Reply
Problem solved by using ImageEn CaptureFromScreen:

var
  MyIO: TImageEnIO;
begin
  MyIO := TImageEnIO.Create(nil);
  try
    MyIO.CaptureFromScreen(iecsSpecifiedWindow, -1, HtPanelPreview.Handle);
    MyIO.IEBitmap.CopyToClipboard(True, True);
  finally
    MyIO.Free;
  end;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: