[Lazarus] create bng with transparent background

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] create bng with transparent background

Free Pascal - Lazarus mailing list
Hello,

is there a way to create a png with transparent background?

I tried the suggestion here

http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-How-to-create-a-transparent-PNG-td4047716.html

to set the brush to bsClear but it doesn't work.
I also tried with a TFPMemoryImage using either a brush or a pen with
alphaTransparent but I couldn't have a transparent png, the background
is always black.

Regards
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] create bng with transparent background

Free Pascal - Lazarus mailing list
On 2020/06/10 13:57, Luca Olivetti via lazarus wrote:

> Hello,
>
> is there a way to create a png with transparent background?
>
> I tried the suggestion here
>
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-How-to-create-a-transparent-PNG-td4047716.html 
>
>
> to set the brush to bsClear but it doesn't work.
> I also tried with a TFPMemoryImage using either a brush or a pen with
> alphaTransparent but I couldn't have a transparent png, the background
> is always black.


The brush.style:=bsClear merely dictates how any next additive drawing
will fill its specific background area, for instance if you were to add
Text to the image it will draw the text without a background, which is
useful if you wish to write on pictures or transparent PNGs.

I think the best way to make a transparent PNG currently, is to do what
you did, but then paint at least the upper left corner pixel with a
transparency of 1 and not Zero, which you still won't see, however, may
I suggest using the very useful BGRA Bitmap package? Then it simply
becomes a question of:

uses
   ... BGRABitmap, BGRABitmapTypes, ...

var
   bmp : TBGRABitmap;
   png : TPortableNetworkGraphic;

...

   bmp := TBGRABitmap.Create( neededWidth, neededHeight );
   png := TPortableNetworkGraphic.Create;

   bmp.FillRect( bmp.ClipRect, BGRAPixelTransparent, dmSet );
   png.Assign( bmp );


Done. Obviously the real advantage of those BGRA tools is when you
actually wish to draw stuff on the image.


Also, how do you know the output PNG file is not transparent? I ask
because windows and windows viewers will sometimes show a perfectly
transaprent PNG with a Black/White background. The only safe way to know
is to open it in Paint or GIMP or such. (Linux typically doesn't lie
like that, but any specific viewer may of course still do it some
arbitrary way. A graphic editor is obliged to show the real content.)

Note: That BGRAPixelTransaprent is simply an internally defined TPixel
with R G B and Alpha all set to 0, so you can also make up your own
transparent pixel and use that in stead.

Good luck!


--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] create bng with transparent background

Free Pascal - Lazarus mailing list
El 10/6/20 a les 14:52, R.Smith via lazarus ha escrit:

> I think the best way to make a transparent PNG currently, is to do what
> you did, but then paint at least the upper left corner pixel with a
> transparency of 1 and not Zero, which you still won't see, however, may
> I suggest using the very useful BGRA Bitmap package? Then it simply
> becomes a question of:

Yes, that's what I finally did, but it's overkill considering that I
just need to generate a circle with a specified color.

>
> Also, how do you know the output PNG file is not transparent? I ask
> because windows and windows viewers will sometimes show a perfectly
> transaprent PNG with a Black/White background. The only safe way to know
> is to open it in Paint or GIMP or such. (Linux typically doesn't lie
> like that, but any specific viewer may of course still do it some
> arbitrary way. A graphic editor is obliged to show the real content.)


I loaded them in firefox (which is the intended usage since the
application is a webserver).

Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus