Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2003-11

PNG and resource

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Darek Mazur

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

Reply by email

Darek Mazur
to Darek Mazur

Hi
I tested XPM before, its work fine but I have many bitmaps in BMP I can't find good tools to convert BMP to XPM
and I think that use PNG will be great

Darek

Earlier message 42 lines
----- Original Message ----- From: "Tony Maro" To: Sent: Monday, November 10, 2003 1:08 AM Subject: Re: [lazarus] PNG and resource > Darek Mazur wrote: > > >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. > > > > Try something like this: > > Create your graphic, for instance "mypicture.xpm". (Pixmap's work great) > > Then convert it to a resource at the command line: > > lazres mygraphicresource.lrs mypicture.xpm > > In your code use: > > MyGraphic := TPixmap.Create; > MyGraphic.LoadFromLazarusResource('mypicture'); > > in the Initialization section at the end of the unit be sure to add: > > {$I mygraphicresource.lrs} // inserts the resource into the unit > > > -Tony > > _________________________________________________________________ > To unsubscribe: mail with > "unsubscribe" as the Subject > archives at http://www.lazarus.freepascal.org/mailarchives >

Reply by email

Tony Maro
to Darek Mazur: Hi I've try use resources like in delphi I've notice that no function to load bitmap from…
Darek Mazur wrote 7 lines
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.

Try something like this:

Create your graphic, for instance "mypicture.xpm". (Pixmap's work great)

Then convert it to a resource at the command line:

lazres mygraphicresource.lrs mypicture.xpm

In your code use:

MyGraphic := TPixmap.Create;
MyGraphic.LoadFromLazarusResource('mypicture');

in the Initialization section at the end of the unit be sure to add:

{$I mygraphicresource.lrs} // inserts the resource into the unit

-Tony

Reply by email

David Creelman
to Darek Mazur: Hi I've try use resources like in delphi I've notice that no function to load bitmap from…
Darek Mazur wrote
Hi I tested XPM before, its work fine but I have many bitmaps in BMP I can't find good tools to convert BMP to XPM

Have you tried using the netpbm tools, there is a utility amongst them called bmptoppm and then a utility called ppmtoxpm. I use these at work, they're pretty useful.

DC

Show quoted text 51 lines
and I think that use PNG will be great Darek ----- Original Message ----- From: "Tony Maro" To: Sent: Monday, November 10, 2003 1:08 AM Subject: Re: [lazarus] PNG and resource > Darek Mazur wrote: > > >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. > > > > Try something like this: > > Create your graphic, for instance "mypicture.xpm". (Pixmap's work great) > > Then convert it to a resource at the command line: > > lazres mygraphicresource.lrs mypicture.xpm > > In your code use: > > MyGraphic := TPixmap.Create; > MyGraphic.LoadFromLazarusResource('mypicture'); > > in the Initialization section at the end of the unit be sure to add: > > {$I mygraphicresource.lrs} // inserts the resource into the unit > > > -Tony > > _________________________________________________________________ > To unsubscribe: mail with > "unsubscribe" as the Subject > archives at http://www.lazarus.freepascal.org/mailarchives > _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives

Reply by email

Mattias Gaertner
to Darek Mazur: Hi I've try use resources like in delphi I've notice that no function to load bitmap from…
Show quoted text 14 lines
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 ,

because a TPortableNetworkBitmap can load .png files, but not bmp/xpm files.

I need load resource from different formats

Use TPicture.

Mattias

Show quoted text 39 lines
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 _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives

Reply by email