Recent

Author Topic: Copy BGRABitmap to Clipboard with Transparency  (Read 3579 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Copy BGRABitmap to Clipboard with Transparency
« on: August 27, 2019, 06:41:22 pm »
I am copying a transparent BGRABitmap to the clipboard

It copies fine, but it has no transparency.. just black where it should be transparent.

My Code so far...

Code: Pascal  [Select][+][-]
  1.  
  2. Clipboard.Assign(theBMP.Bitmap);
  3.  
  4.  


Any help would be appreciated.
« Last Edit: August 30, 2019, 09:28:37 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Quick Q... Copy BGRABitmap to Clipboard with Transparency
« Reply #1 on: August 27, 2019, 07:24:11 pm »
Here is another solution I have worked out... but it is still black.

Anyone can help?

Code: Pascal  [Select][+][-]
  1.  
  2. Var
  3.  PIC : TPicture;
  4.  BGRA: TBGRABitmap;
  5. Begin
  6. PIC:= TPicture.Create;
  7.  Try
  8.   BGRA:= TBGRABitmap.Create(theBMP);
  9.    Try
  10.     PIC.Assign(BGRA);
  11.    Finally
  12.     BGRA.Free;
  13.    End;
  14.    Clipboard.Assign(PIC);
  15.  Finally
  16.   PIC.Free;
  17.  End;
  18.  
  19.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: Quick Q... Copy BGRABitmap to Clipboard with Transparency
« Reply #2 on: August 27, 2019, 08:47:04 pm »
Check on LazPaint uClipboard.pas
https://github.com/bgrabitmap/lazpaint/blob/master/lazpaint/uclipboard.pas

There you have procedure CopyToClipboard(bmp: TBGRABitmap);

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Quick Q... Copy BGRABitmap to Clipboard with Transparency
« Reply #3 on: August 28, 2019, 02:14:19 am »
Check on LazPaint uClipboard.pas
https://github.com/bgrabitmap/lazpaint/blob/master/lazpaint/uclipboard.pas

There you have procedure CopyToClipboard(bmp: TBGRABitmap);

Okay... plugged in the procedure. get error on TFPWriterBMP identifier not found.

What uses do I need for this?
I do have this BGRABitmap uses.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Quick Q... Copy BGRABitmap to Clipboard with Transparency
« Reply #4 on: August 28, 2019, 02:19:28 am »
I found some code with lots of uses, so I had to try one by one.

It's this one... FPWriteBMP

Now I get an error on this line... identifier not found.

Clipboard.AddFormat(bgraClipboardFormat, stream);
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Quick Q... Copy BGRABitmap to Clipboard with Transparency
« Reply #5 on: August 28, 2019, 02:30:30 am »
Fixed the last error


Had to declare var
bgraClipboardFormat: TClipboardFormat;

The project compiles and copies the file... it's still black instead of transparent.


Also, I tried the Copy function in LAZ Paint and that copied BMP has black instead of transparent too.

The program I use to view transparent PNG's is IFranView, and that program allows the viewing and pasting of Transparent PNG's
« Last Edit: August 28, 2019, 02:18:41 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #6 on: August 30, 2019, 09:30:13 am »
Still needing answer to how to get rid of black background copy.

The LAZPaint also does the same thing... black background too
« Last Edit: August 31, 2019, 02:29:14 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #7 on: September 03, 2019, 06:13:52 pm »
LAINZ or CIRCULAR... can you help?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #8 on: September 05, 2019, 04:59:52 pm »
I copy a transparent image in LazPaint and then paste it in LazPaint and it has transparency.

But, I copy that image and paste it in MSPaint and it has black background, so seems that it works only inside LazPaint application, not outside.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #9 on: September 05, 2019, 06:17:13 pm »
Hi

the method in uClipboard.pas use BMP format so, by default transparency is not supported by this format.
Perhaps try changing TFPWriterBMP by PNG writer. And instead of using : "pcfBitmap" witch is equal to "image/bmp" as mime type. Try to change it by 'image/png'

Cheers

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #10 on: September 05, 2019, 06:42:59 pm »
Yes. The only formats that preserve transparency are PNG and the deprecated 8bit GIF.

And of cause the proprietary formats of GIMP and PhotoShop.

In the BGRA units you will find

Code: Pascal  [Select][+][-]
  1. procedure TBGRACustomBitmap.SaveToStreamAsPng(Str: TStream);  
  2.  

Connect the stream with the clipboard.

Winni

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #11 on: September 12, 2019, 04:49:26 pm »
Try again with the new uclipboard of the newest LazPaint 7.0.6
https://github.com/bgrabitmap/lazpaint/blob/master/lazpaint/uclipboard.pas

It now supports transparency, for example tested with Inkscape and GIMP, and both receives the image with transparency.

According to circular is hard to support all formats, since propietary applications use different formats for clipboard. But if the application supports PNG it will work.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #12 on: November 03, 2019, 04:12:06 pm »
I tried the transparency... and it worked in Affinity Photo (and I am sure for other painting apps too)

But, it didn't work in iFranView Image viewer. And I know that supports alpha images.

But anyway... I am aware that transparency is not supported in every application.

But, I think I am done with this thread.


BTW.... Every time I click the X (close) button to exit out of the application I get an error. See below  screenshot
this is just opening LazPaint and doing nothing, and then exiting the program.

Thought you may want to know.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #13 on: November 03, 2019, 06:39:08 pm »
I tried the transparency... and it worked in Affinity Photo (and I am sure for other painting apps too)
Cool

Quote
But, it didn't work in iFranView Image viewer. And I know that supports alpha images.
Yes, some programs support alpha images but not alpha clipboard.

Quote
BTW.... Every time I click the X (close) button to exit out of the application I get an error. See below  screenshot
this is just opening LazPaint and doing nothing, and then exiting the program.

Thought you may want to know.
Strange. Anyone else this error?
Conscience is the debugger of the mind

Segator

  • Full Member
  • ***
  • Posts: 168
    • https://github.com/Nenirey
Re: Copy BGRABitmap to Clipboard with Transparency
« Reply #14 on: November 08, 2019, 05:28:27 pm »
My project support clipboard transparent images :D it use BGRABitmap library and Vampyre Image library
https://github.com/Nenirey/LazView
https://sourceforge.net/projects/lazview/
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

 

TinyPortal © 2005-2018