[Lazarus] TImage and PNG (on linux)

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

[Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
Hi, I was testing a sample project and found that on Windows, handling
of PNGs with transparent backgrounds is working ok, but on Linux it
doesn't work as expected. The image is a black line on the top of the
image, with a Gaussian Blur applied on Photoshop, then saved to PNG with
transparent background.

I attached an image showing what I get on Windows vs Linux, also the
original image.

Thanks in advance,
--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

png_transparent.jpg (12K) Download Attachment
sombra_top_horiz.png (288 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage and PNG (on linux)

Felipe Monteiro de Carvalho
No test source code?

--
Felipe Monteiro de Carvalho

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

Re: [Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
On 2011-04-10 22:45:22 +0200, Felipe Monteiro de Carvalho wrote:
> No test source code?
>
> --
> Felipe Monteiro de Carvalho

Just place a TImage on a form, then load the attached png
(sombra_bottom_horiz.png) into it.

--
Leonardo M. Ramé
http://leonardorame.blogspot.com

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

Re: [Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
On 2011-04-10 17:49:03 -0300, Leonardo M. Ramé wrote:
> On 2011-04-10 22:45:22 +0200, Felipe Monteiro de Carvalho wrote:
> > No test source code?
> >
> > --
> > Felipe Monteiro de Carvalho
>
> Just place a TImage on a form, then load the attached png
> (sombra_bottom_horiz.png) into it.
>

Here it is anyway.

--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

test.7z (80K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage and PNG (on linux)

silvioprog
2011/4/10 Leonardo M. Ramé <[hidden email]>:

> On 2011-04-10 17:49:03 -0300, Leonardo M. Ramé wrote:
>> On 2011-04-10 22:45:22 +0200, Felipe Monteiro de Carvalho wrote:
>> > No test source code?
>> >
>> > --
>> > Felipe Monteiro de Carvalho
>>
>> Just place a TImage on a form, then load the attached png
>> (sombra_bottom_horiz.png) into it.
>>
>
> Here it is anyway.
>
> --
> Leonardo M. Ramé
> http://leonardorame.blogspot.com
This error appears to me too: :(

[TImage] http://imagebin.org/147499
[TrayIcon] http://imagebin.org/147500 (normal transparency only in
Windows >:(~ ).

Test in attached.

Lazarus 0.9.31 r30018M FPC 2.5.1 i386-linux-gtk 2

--
Silvio Clécio
=============================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

test.zip (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TImage and PNG (on linux)

Marco van de Voort
In reply to this post by Leonardo M. Ramé
On Sun, Apr 10, 2011 at 05:39:19PM -0300, Leonardo M. Ram? wrote:
> Hi, I was testing a sample project and found that on Windows, handling
> of PNGs with transparent backgrounds is working ok, but on Linux it
> doesn't work as expected. The image is a black line on the top of the
> image, with a Gaussian Blur applied on Photoshop, then saved to PNG with
> transparent background.
>
> I attached an image showing what I get on Windows vs Linux, also the
> original image.

Afaik there is already a report for this in mantis.

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

Re: [Lazarus] TImage and PNG (on linux)

Marc Weustink-2
In reply to this post by Leonardo M. Ramé
Leonardo M. Ramé wrote:
> Hi, I was testing a sample project and found that on Windows, handling
> of PNGs with transparent backgrounds is working ok, but on Linux it
> doesn't work as expected. The image is a black line on the top of the
> image, with a Gaussian Blur applied on Photoshop, then saved to PNG with
> transparent background.
>
> I attached an image showing what I get on Windows vs Linux, also the
> original image.

The current linux-gtk implementation has only a 1 bit alpha

Marc

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

Re: [Lazarus] TImage and PNG (on linux)

Krzysztof
In reply to this post by Leonardo M. Ramé
This is known issue. GTK have no alpha yet but I created set of components which partially solve this problem by using BGRABitmap class, details: http://www.lazarus.freepascal.org/index.php/topic,12411.0.html . Although there is no TImage yet but I can try create it.
For TrayIcon on GTK you must rebuild lazarus with -dUseStatusIcon switch. If tray still have no alpha then you must add this 3 lines posted by TrUsTeR:
After this tray icon works perfect in my case.

2011/4/10 Leonardo M. Ramé <[hidden email]>
Hi, I was testing a sample project and found that on Windows, handling
of PNGs with transparent backgrounds is working ok, but on Linux it
doesn't work as expected. The image is a black line on the top of the
image, with a Gaussian Blur applied on Photoshop, then saved to PNG with
transparent background.

I attached an image showing what I get on Windows vs Linux, also the
original image.

Thanks in advance,
--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



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

Re: [Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
On 2011-04-12 19:22:36 +0200, Krzysztof wrote:

>    This is known issue. GTK have no alpha yet but I created set of components
>    which partially solve this problem by using BGRABitmap class, details:
>    http://www.lazarus.freepascal.org/index.php/topic,12411.0.html . Although
>    there is no TImage yet but I can try create it.
>    For TrayIcon on GTK you must rebuild lazarus with -dUseStatusIcon switch.
>    If tray still have no alpha then you must add this 3 lines posted by
>    TrUsTeR:
>    http://www.lazarus.freepascal.org/index.php/topic,6583.0.html
>    After this tray icon works perfect in my case.
>    2011/4/10 Leonardo M. Rame <[hidden email]>
>
>      Hi, I was testing a sample project and found that on Windows, handling
>      of PNGs with transparent backgrounds is working ok, but on Linux it
>      doesn't work as expected. The image is a black line on the top of the
>      image, with a Gaussian Blur applied on Photoshop, then saved to PNG with
>      transparent background.
>
>      I attached an image showing what I get on Windows vs Linux, also the
>      original image.
>
>      Thanks in advance,
>      --
>      Leonardo M. Rame
>      http://leonardorame.blogspot.com
>      --
>      _______________________________________________
>      Lazarus mailing list
>      [hidden email]
>      http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

> --
> _______________________________________________
> Lazarus mailing list
> [hidden email]
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Well, I don't really need TImage, but TPicture. What I need is to be
able to use TCanvas methods to copy this picture into another TCanvas.

Does your component allows this?



--
Leonardo M. Ramé
http://leonardorame.blogspot.com

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

Re: [Lazarus] TImage and PNG (on linux)

Krzysztof
So if you want operate on bitmaps and canvas then maybe it is better to read about BGRABitmap and do this same things which i'm doing in my components. This is very interesting class. You can load PNG image to this class and draw wherever you want similar like with canvas (but with alpha). Details:
and few tutorials (with nice effects):
This is crossplatform library

2011/4/12 Leonardo M. Ramé <[hidden email]>
On 2011-04-12 19:22:36 +0200, Krzysztof wrote:
>    This is known issue. GTK have no alpha yet but I created set of components
>    which partially solve this problem by using BGRABitmap class, details:
>    http://www.lazarus.freepascal.org/index.php/topic,12411.0.html . Although
>    there is no TImage yet but I can try create it.
>    For TrayIcon on GTK you must rebuild lazarus with -dUseStatusIcon switch.
>    If tray still have no alpha then you must add this 3 lines posted by
>    TrUsTeR:
>    http://www.lazarus.freepascal.org/index.php/topic,6583.0.html
>    After this tray icon works perfect in my case.
>    2011/4/10 Leonardo M. Rame <[hidden email]>
>
>      Hi, I was testing a sample project and found that on Windows, handling
>      of PNGs with transparent backgrounds is working ok, but on Linux it
>      doesn't work as expected. The image is a black line on the top of the
>      image, with a Gaussian Blur applied on Photoshop, then saved to PNG with
>      transparent background.
>
>      I attached an image showing what I get on Windows vs Linux, also the
>      original image.
>
>      Thanks in advance,
>      --
>      Leonardo M. Rame
>      http://leonardorame.blogspot.com
>      --
>      _______________________________________________
>      Lazarus mailing list
>      [hidden email]
>      http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

> --
> _______________________________________________
> Lazarus mailing list
> [hidden email]
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Well, I don't really need TImage, but TPicture. What I need is to be
able to use TCanvas methods to copy this picture into another TCanvas.

Does your component allows this?



--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



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

Re: [Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
On 2011-04-12 20:18:48 +0200, Krzysztof wrote:

>    So if you want operate on bitmaps and canvas then maybe it is better to
>    read about BGRABitmap and do this same things which i'm doing in my
>    components. This is very interesting class. You can load PNG image to this
>    class and draw wherever you want similar like with canvas (but with
>    alpha). Details:
>    http://wiki.lazarus.freepascal.org/BGRABitmap
>    and few tutorials (with nice effects):
>    http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial
>    This is crossplatform library
>
You are right Krzysztof, in fact, I adapted my code to BGRABitmap and it
worked like a charm.

Just a note. I miss the LoadFromLazResource method, like TPicture. Do you plan
to add this feature?.

--
Leonardo M. Ramé
http://leonardorame.blogspot.com

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

Re: [Lazarus] TImage and PNG (on linux)

Krzysztof
I am not the author of BGRABitmap class but I think it is easy to assign bitmap from resource to BGRABitmap class. You can load image from resource using TResourceStream (there is tutorial on wiki) and then call BGRABitmap.LoadFromStream(MyResourceStream)

2011/4/12 Leonardo M. Ramé <[hidden email]>
On 2011-04-12 20:18:48 +0200, Krzysztof wrote:
>    So if you want operate on bitmaps and canvas then maybe it is better to
>    read about BGRABitmap and do this same things which i'm doing in my
>    components. This is very interesting class. You can load PNG image to this
>    class and draw wherever you want similar like with canvas (but with
>    alpha). Details:
>    http://wiki.lazarus.freepascal.org/BGRABitmap
>    and few tutorials (with nice effects):
>    http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial
>    This is crossplatform library
>
You are right Krzysztof, in fact, I adapted my code to BGRABitmap and it
worked like a charm.

Just a note. I miss the LoadFromLazResource method, like TPicture. Do you plan
to add this feature?.

--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



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

Re: [Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
On 2011-04-12 20:36:34 +0200, Krzysztof wrote:
>    I am not the author of BGRABitmap class but I think it is easy to assign
>    bitmap from resource to BGRABitmap class. You can load image from resource
>    using TResourceStream (there is tutorial on wiki) and then call
>    BGRABitmap.LoadFromStream(MyResourceStream)

I tried this and got an 'ExceptionException Unknown/Unsupported PCX
image type'. The resource contains a PNG image.

  lRes := TLazarusResourceStream.Create('sombra_top_horiz', 'PNG');
  try
    lRes.Position:= 0;
    FMyTBGRABitmap.LoadFromStream(lRes);
  finally
    lRes.Free;
  end;

Any workaround?
--
Leonardo M. Ramé
http://leonardorame.blogspot.com

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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

Re: [Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé
On 2011-04-12 16:09:07 -0300, Leonardo M. Ramé wrote:

> On 2011-04-12 20:36:34 +0200, Krzysztof wrote:
> >    I am not the author of BGRABitmap class but I think it is easy to assign
> >    bitmap from resource to BGRABitmap class. You can load image from resource
> >    using TResourceStream (there is tutorial on wiki) and then call
> >    BGRABitmap.LoadFromStream(MyResourceStream)
>
> I tried this and got an 'ExceptionException Unknown/Unsupported PCX
> image type'. The resource contains a PNG image.
>
>   lRes := TLazarusResourceStream.Create('sombra_top_horiz', 'PNG');
>   try
>     lRes.Position:= 0;
>     FMyTBGRABitmap.LoadFromStream(lRes);
>   finally
>     lRes.Free;
>   end;
>
> Any workaround?

I found a solution. To load the stream with a TFPReader, here's the
code, for the record:

var
  lResTop: TLazarusResourceStream;
  lPngReader: TFPReaderPNG;
begin
  inherited Create(TheOwner);
  FShadowTop := TBGRABitmap.Create;
  FShadowBottom := TBGRABitmap.Create;

  lPngReader := TFPReaderPNG.create;
  lResTop := TLazarusResourceStream.Create('sombra_top_horiz', 'PNG');
  try
    lResTop.Position:= 0;
    FShadowTop.LoadFromStream(lResTop, lPngReader);
  finally
    lResTop.Free;
    lPngReader.Free;
  end;  


--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus