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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Render a component screenshot with transparent background?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Dec 19 2023 : 02:22:43
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.
1   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Dec 19 2023 : 05:21:37
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;