Leonardo M. Ram? wrote 18 lines
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;