[Lazarus] TImage and PNG (on linux)

Leonardo M. Ramé l.rame at griensu.com
Tue Apr 12 21:19:04 CEST 2011


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




More information about the Lazarus mailing list