Recent

Author Topic: BGRABitmap to TImage fault  (Read 5474 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BGRABitmap to TImage fault
« Reply #15 on: May 06, 2021, 02:01:22 pm »
Hi!

I deleted the TBitmap part from the code to enshure that only PNGs are loaded.


The behaviour differs between gtk2 and Win7 - just tested.

* In all  cases the transparent pixels are 0/0/0/0 - good.
* In all cases a BGRAbitmap.draw(Image.canvas,0,0) converts the transparent pixels to black
* BGRAbitmap.draw(Image.canvas,0,0, false): In Windows the pixels appear in the background color, while gtk2 shows nothing.
* Image.canvas.CopyRect: In gtk2 the desired result is shown while Windows behaves like BGRAbitmap.draw(Image.canvas,0,0, false): The opaque pixel are shown in the backpmground color.

All results except copyrect and gtk2 are not satisfying.

Winni
« Last Edit: May 06, 2021, 02:06:03 pm by winni »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BGRABitmap to TImage fault
« Reply #16 on: May 06, 2021, 05:11:11 pm »
Hi!

Now I got a working trick!

Dont draw on the canvas of the TImage but on the image.picture.PNG.Canvas!


Code: Pascal  [Select][+][-]
  1. image.Draw(Image1.Picture.PNG.Canvas,0,0,false);    

That preserves the transparency and everything is like it should!

Only tested with Linux/gtk2

Winni


PS.: Just tested with Win7: Works fine!
« Last Edit: May 06, 2021, 05:32:27 pm by winni »

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: BGRABitmap to TImage fault
« Reply #17 on: May 06, 2021, 07:33:19 pm »
Well you could try to use uclipboard though it depend on some other units to fetch files online.

I am wonder, I can see CF_DIB and CF_DIBV5. Maybe the V5 one handles transparency. Though I am not sure how you could make the difference from the LCL.

I was also quite confused about the clipboard situation on Windows.
« Last Edit: May 06, 2021, 07:35:59 pm by circular »
Conscience is the debugger of the mind

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BGRABitmap to TImage fault
« Reply #18 on: May 06, 2021, 08:50:13 pm »

I am wonder, I can see CF_DIB and CF_DIBV5. Maybe the V5 one handles transparency. Though I am not sure how you could make the difference from the LCL.


Hi!

CF_DIBV5 contains a bV5AlphaMask.  That is the answer to all the questions.

M$ doc: https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapv5header

How the LCL handles this I don't know.

Winni

schlueter550v

  • New Member
  • *
  • Posts: 14
Re: BGRABitmap to TImage fault
« Reply #19 on: May 07, 2021, 08:21:27 am »
hello circular,
hello winni,

for fun i tried the same with Lazpaint on Windows. It doesnt work there too. you can see it in the attchment.

I am clueless right now

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: BGRABitmap to TImage fault
« Reply #20 on: May 07, 2021, 08:37:26 am »
Does it work with any image software?
Conscience is the debugger of the mind

schlueter550v

  • New Member
  • *
  • Posts: 14
Re: BGRABitmap to TImage fault
« Reply #21 on: May 07, 2021, 10:19:34 am »
Hello circular,

i tested a few things:

From Gimp to LazPaint it works, PNG in Clipboard
From Firefox to Lazpaint, black Background
From Edge to Lazpaint, black background,
From Paint to LazPaint, white background. Seems Paint canverts Transparency to white
From Faststone Viewer, white background.

In the attachment ar the example with the Clipboard content

Best Regards
schlueter550v

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BGRABitmap to TImage fault
« Reply #22 on: May 07, 2021, 10:30:14 am »
Hi!

All these tests respect transpareny in both directions with a PNG:

Gimp <--> Inkskape
KolourPaint <--> Inkskape
KolourPaint <--> Gimp

Winni

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: BGRABitmap to TImage fault
« Reply #23 on: May 07, 2021, 05:05:48 pm »
I guess Inkscape provides a PNG as well.

If the source application doesn't provide an alpha channel, then there is nothing to do about it.  :'(
Conscience is the debugger of the mind

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BGRABitmap to TImage fault
« Reply #24 on: May 07, 2021, 05:52:51 pm »
I guess Inkscape provides a PNG as well.

If the source application doesn't provide an alpha channel, then there is nothing to do about it.  :'(

Hi!
Yes, all tests were done with a PNG.

The source applications like Gimp provide an alpha channel and the transparency is transported via the clipboard. But the alpha channel disappears when drawn on a TImage.canvas or a Form.canvas.  But it stays if the BGRAbitmap is drawn on an Image.picture.PNG.canvas.

Either the problem can be solved or it should be documented.

Winni

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: BGRABitmap to TImage fault
« Reply #25 on: May 07, 2021, 09:05:38 pm »
The fact that the canvas does not store alpha channel is not new. That's another subject here. Isn't it?
Conscience is the debugger of the mind

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: BGRABitmap to TImage fault
« Reply #26 on: May 07, 2021, 09:21:55 pm »
The fact that the canvas does not store alpha channel is not new. That's another subject here. Isn't it?

Hi!


But that was the original question of schlueter550v

Winni

schlueter550v

  • New Member
  • *
  • Posts: 14
Re: BGRABitmap to TImage fault
« Reply #27 on: May 07, 2021, 09:26:26 pm »
Hello circular,
hello winni,

my initial question is answered. Maybe we need a new thread for the alpha problem?? Anyway i answer one more time to it:


If the source application doesn't provide an alpha channel, then there is nothing to do about it.  :'(

doesnt CF_DIBV5 contain an alpha channel like thing?
In Microsofts documentation on
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapv5header
they say something like this:

Quote
bV5AlphaMask

Color mask that specifies the alpha component of each pixel.


I have no clue how to read them properly.
I am a very beginner with FPC and Lazarus.

The only thing i found to CF_DIBV5 in Pascal is an old Delphi Code that uses GR32.
https://stackoverflow.com/a/12265496
I dont know if this works in Lazarus. Thats too much for me as beginner.

If we have to open a new thread, please tell me?

Best Regards
schlueter550v

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
Re: BGRABitmap to TImage fault
« Reply #28 on: May 08, 2021, 05:24:18 am »
Well in theory there can be some alpha channel in BMP files, but in practice it is not much used. In BGRABitmap and LazPaint, I propose to use it, but many programs cannot load them.

Maybe try to paste the image in other software like Gimp, PaintShopPro, Paint.NET etc. to see if any can find some transparency information.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018