Recent

Author Topic: Outputting a transparent PNGimage with BGRABitmap  (Read 575 times)

clintonb

  • New Member
  • *
  • Posts: 21
Outputting a transparent PNGimage with BGRABitmap
« on: February 03, 2025, 06:59:45 pm »
I have code that used a dll to output a png with transparent pixels but i cant find a .so for linux.  I found an article that shows how to use TBGRABitmap to do this.  I just copied from a control to test it out by saying :

  tempsaveimage.canvas.copyrect(rect(0,0,panel8.width,panel8.height),panelcanvas,rect(0,0,panel8.width,panel8.height));

tempsaveimage.ReplaceColor(BGRA(255,0,0,255),BGRAPixelTransparent);
         

Then i saved it to a file by just calling tempsaveimage.savetofile. 

All works and it actually gives me an output that is a transparent PNG which is great.  What is strange is that imagemagik doesnt recognize the transparency but Gimp does.  Ive spent the last 3 hours comparing a png file that works and the one that i generated with TBGRABitmap and for the life of me i cant see it.  Is this the wrong way to go savethe output to a file? Perhaps there is a pixelformat that needs to be specified?

clintonb

  • New Member
  • *
  • Posts: 21
Re: Outputting a transparent PNGimage with BGRABitmap
« Reply #1 on: February 03, 2025, 09:00:38 pm »
Its bizarre but i suppose its like saving a jpg with a .bmp extension and certain programs will tell you its not a valid bitmap where others look past the obvious and use the header information.  Its not ideal but opening it in gimp and just re-saving it seems patch what TBGRABitmap misses and everything works.  I will have to dig through this a bit closer to figure just what that is.

TRon

  • Hero Member
  • *****
  • Posts: 4162
Re: Outputting a transparent PNGimage with BGRABitmap
« Reply #2 on: February 03, 2025, 09:05:51 pm »
It is impossible to provide any meaningful feedback without knowing what you actually did in code and what the outcome of it is.

Although there is only a single real one, transparency can mean 2 different things depending on the point of view of whatever program. Note that most graphical viewers/editor do not have a clue (even if they are expensive commercial products).
Today is tomorrow's yesterday.

clintonb

  • New Member
  • *
  • Posts: 21
Re: Outputting a transparent PNGimage with BGRABitmap
« Reply #3 on: February 04, 2025, 09:45:43 am »
Im not sure i understand why this is an issue given how many programs had a problem with it but i used the replacecolor to change the background to BGRAPixeltransparent as per a few tutorials and this seems to show opaque.  Looking in Gimp, it is simply a pixel color of black with no opacity or BGRA(0,0,0,0).  Setting this to any non black color with 0 opacity makes the problem go away.

Khrys

  • Full Member
  • ***
  • Posts: 177
Re: Outputting a transparent PNGimage with BGRABitmap
« Reply #4 on: February 04, 2025, 11:32:41 am »
You'll need to show your full/exact code and/or upload the broken  .png  if you want anyone to analyze it further.

 

TinyPortal © 2005-2018