[lazarus] PNG and resource

Darek Mazur darekm at emadar.com
Sun Nov 9 18:44:27 EST 2003


Hi

I've try use resources like in delphi
I've notice that no function to load bitmap from resource (only truecolor)
Than try PNG to store button image but in graphics.pp is bug or I can't
understand it.

class tBitmap has
  procedure ReadStream(Stream: TStream; Size: Longint); virtual;

and class tPortableNetworkBitmap has
  procedure ReadStream(Stream: TStream; Size: Longint); override;

but there are not conected ,
I need  load resource from different formats

I think it will be better work when we write some like this in each stage of
inheritation

 procedure TBitmap.LoadFromLazarusResource(const ResName: String);
var
  ms:TMemoryStream;
  res:TLResource;
begin
  res:=LazarusResources.Find(ResName);
  if (res=nil) or (res.Value='') or not
LazarusResourceTypeValid(res.ValueType)
  then  begin

    inherited;
   ^^^^^^^^


    exit;
end;
  ms:=TMemoryStream.Create;
  try
    ms.Write(res.Value[1],length(res.Value));
    ms.Position:=0;
    LoadFromStream(ms);
  finally
    ms.Free;
  end;
end;


I can work on this, but I don't know if it is the better solution

darek






More information about the Lazarus mailing list