Author |
Topic  |
|
PeterPanino
   
978 Posts |
Posted - May 12 2025 : 14:58:39
|
After copying the current image to the clipboard, no CLIPBOARD OWNER can be retrieved with: Winapi.Windows.GetClipboardOwner

However, when copying from any other (graphics) application, the clipboard owner can always be retrieved, for example:

Or:

Look at this demo project that demonstrates this issue:
attach/PeterPanino/2025512145723_ImageEnViewCopyToClipboard_Test.zip 77.62 KB
Please fix this issue. Thank you! |
|
xequte
    
39015 Posts |
Posted - May 12 2025 : 20:04:36
|
Hi Peter
Please email me for the fix in the latest beta.
Nigel Xequte Software www.imageen.com
|
 |
|
PeterPanino
   
978 Posts |
Posted - May 13 2025 : 04:35:51
|
Meanwhile, I created a simple workaround by using a TImage (!):
procedure TForm1.FormCreate(Sender: TObject);
begin
with ImageEnView1.IO do
LoadFromFileAuto(ExecuteOpenDialog());
Image1.Picture.Assign(ImageEnView1.IEBitmap.VclBitmap);
ButtonCopy.Enabled := True;
end;
procedure TForm1.ButtonCopyClick(Sender: TObject);
begin
//ImageEnView1.Proc.CopyToClipboard();
// This works with Winapi.Windows.GetClipboardOwner:
Vcl.Clipbrd.Clipboard.Assign(Image1.Picture);
end;
Now, Winapi.Windows.GetClipboardOwner gets:

Or even shorter and better:
procedure TForm1.ButtonCopyClick(Sender: TObject);
begin
// This does not work with Winapi.Windows.GetClipboardOwner:
//ImageEnView1.Proc.CopyToClipboard();
// This works with Winapi.Windows.GetClipboardOwner:
Vcl.Clipbrd.Clipboard.Assign(ImageEnView1.IEBitmap.VclBitmap);
end; |
 |
|
PeterPanino
   
978 Posts |
Posted - May 13 2025 : 09:16:34
|
Hi Nigel,
Thank you for the newest beta source. I have tried it with these two Copy methods:
//ImageEnView1.Proc.CopyToClipboard();
ImageEnView1.IEBitmap.CopyToClipboard(True, True);
Now, Winapi.Windows.GetClipboardOwner gets the correct Handle - so far so good. But unfortunately, the image copied to the clipboard has a BLACK BACKGROUND (after having loaded a PNG image with transparency):

This coincides with my previous "workaround," where I copied the VCL Bitmap directly to the clipboard:
Vcl.Clipbrd.Clipboard.Assign(ImageEnView1.IEBitmap.VclBitmap);
But IEBitmap.VclBitmap is a TBitmap and as such, the Alpha is lost when copied to the clipboard.
Can you please fix this? Thank you! |
 |
|
PeterPanino
   
978 Posts |
Posted - May 13 2025 : 10:57:07
|
I have created a temporary workaround for this new problem introduced by the latest beta source:
procedure TForm1.FormCreate(Sender: TObject);
begin
with ImageEnView1.IO do
begin
FImageFilePath := ExecuteOpenDialog();
LoadFromFileAuto(FImageFilePath);
end;
ButtonCopy.Enabled := True;
end;
procedure TForm1.ButtonCopyClick(Sender: TObject);
var
TempImage: Vcl.ExtCtrls.TImage;
begin
if not ImageEnView1.HasAlphaChannel() then
ImageEnView1.Proc.CopyToClipboard()
else
begin
TempImage := Vcl.ExtCtrls.TImage.Create(nil);
try
TempImage.Picture.LoadFromFile(FImageFilePath);
Vcl.Clipbrd.Clipboard.Assign(TempImage.Picture);
finally
TempImage.Free;
end;
end;
end; |
 |
|
xequte
    
39015 Posts |
Posted - May 13 2025 : 20:35:21
|
Hi Peter
I'm not seeing that, but I'm using a newer beta.
I've just emailed you the newer beta. If you still see it, please try to reproduce that in one of our demos and give me the precise steps.
Also, what application are you pasting into?
Nigel Xequte Software www.imageen.com
|
 |
|
PeterPanino
   
978 Posts |
Posted - May 14 2025 : 09:13:40
|
I have now found the ultimate copy-to-clipboard method that completely prevents the black background and preserves transparency in all cases:
procedure TForm1.ButtonCopyClick(Sender: TObject);
var
TempImage: Vcl.ExtCtrls.TImage;
TempPicture: Vcl.Graphics.TPicture;
begin
if not ImageEnView1.HasAlphaChannel() then // if image has NO transparency
begin
//CodeSite.Send('TForm1.ButtonCopyClick: NATIVE COPY');
ImageEnView1.Proc.CopyToClipboard();
end
else // if image has transparency (prevents black background!)
begin
//CodeSite.Send('TForm1.ButtonCopyClick: TIMAGE COPY');
TempImage := Vcl.ExtCtrls.TImage.Create(nil);
TempPicture := Vcl.Graphics.TPicture.Create;
try
//TempImage.Picture.LoadFromFile(FImageFilePath); Discarded, as TImage cannot load .GIF files!
TempPicture.Bitmap.Width := ImageEnView1.IEBitmap.Width;
TempPicture.Bitmap.Height := ImageEnView1.IEBitmap.Height;
ImageEnView1.CopyToBitmapWithAlpha(TempPicture.Bitmap, 0, 0); // Ingenious method!!!
TempImage.Picture.Assign(TempPicture);
Vcl.Clipbrd.Clipboard.Assign(TempImage.Picture);
finally
TempPicture.Free;
TempImage.Free;
end;
end;
end;
Here is the demo that demonstrates this:
attach/PeterPanino/20255149239_ImageEnViewCopyToClipboard_Test_V2.zip 78.47 KB
Here is the CF_BITMAP clipboard format after copying with TImage:
 |
 |
|
xequte
    
39015 Posts |
Posted - May 14 2025 : 22:20:24
|
Hi Peter
With the beta, make sure you add these units to one of your project files:
ieNativeJPEG, ieNativePNG, ieNativeJ2K
Are you sure you are getting a transparent background when pasting, and not a white background? As CF_BITMAP should not support transparency.
The "PNG" clipboard format is the most reliable method for transparency support.
Please confirm what applications you are using when pasting.
Nigel Xequte Software www.imageen.com
|
 |
|
xequte
    
39015 Posts |
Posted - May 14 2025 : 22:34:43
|
Pasting a transparent PNG into Fireworks or MS Paint works fine for me:

Nigel Xequte Software www.imageen.com
|
 |
|
xequte
    
39015 Posts |
Posted - May 14 2025 : 22:35:57
|
Also, please give me what text you get for PNG Engines from:
debugInfo := IEGlobalSettings().ImageEnVersion.Status;
Nigel Xequte Software www.imageen.com
|
 |
|
PeterPanino
   
978 Posts |
Posted - May 15 2025 : 06:46:46
|
Hi Nigel,
Now, Proc.CopyToClipboard() does everything I need. It even creates a PNG format in the clipboard:

You can check this with the newest version of my test project:

attach/PeterPanino/20255156501_ImageEnViewCopyToClipboard_Test_V3.zip 78.8 KB
1. Load a PNG image with transparency (like the one in the screenshot)
2. Copy to Clipboard
3. Clear Image
4. Paste from Clipboard: You can see that the pasted image has a transparent background!
5. Get Clipboard Owner gets the correct name!
Nigel, thank you for your excellent work! |
 |
|
|
Topic  |
|