1 (edited by livexox 2020-09-25 00:26:39)

Topic: How to load a png image in a form using only script

Hello, I'm trying to load an image into a form using only script code but this is not working. Please HELP!!!

procedure Form1_OnShow (Sender: TObject; Action: string);
Var  graphics:Tgraphic;
Var  image:TImage;
var  png: TPNGImage;
var  file_path: string;
begin

      //file path
      file_path:= 'image.png';

      //create the image from code
      image:=TImage.create(frm_main);
      image.Picture.LoadFromFile(file_path);
      image.name:='image1';
      image.top:=8;
      image.left:=8;
      image.width:=350;
      image.height:=350;
      image.autosize:=true;
      image.visible:=true;
      image.enabled:=true;

      //free object
      image.free;
end;
Post's attachments

Attachment icon Image.zip 346.92 kb, 247 downloads since 2020-09-25 

Re: How to load a png image in a form using only script

Hello livexox

CAn this snippet hep you ?

function LoadPicture(Filename: string; Image: TdbImage): boolean;
var    Graphic: TGraphic;
          sExt: string;
begin
    result := False;
    sExt := LowerCase(ExtractFileExt(Filename));

    if sExt='.bmp' then
    begin
        Graphic := TBitmap.Create;
        Graphic.LoadFromFile(Filename);
        Form1.Image1.Picture.Bitmap.Assign(Graphic);
        Graphic.Free;
    end else
    if sExt='.jpg' then
    begin
        Graphic := TJpegImage.Create;
        Graphic.LoadFromFile(Filename);
        Form1.Image1.Picture.Bitmap.Assign(Graphic);
        Graphic.Free;
    end else
    if sExt='.png' then
    begin
        Graphic := TPngImage.Create;
        Graphic.LoadFromFile(Filename);
        Form1.Image1.Picture.Bitmap.Assign(Graphic);
        Graphic.Free;
    end else
    if sExt='.gif' then
    begin
        Graphic := TGifImage.Create;
        Graphic.LoadFromFile(Filename);
        Form1.Image1.Picture.Bitmap.Assign(Graphic);
        Graphic.Free;
    end else ShowMessage('format d''image son supporté');
end;

JB

Re: How to load a png image in a form using only script

I'm trying to display an picture without an image object in the form, so I can dynamically add as many images as I want using just code.

Form1.Image1.Picture.Bitmap.Assign(Graphic);      <-- this was manually dragged in the form

Re: How to load a png image in a form using only script

any other suggestions will be helpful!!!

Re: How to load a png image in a form using only script

livexox wrote:

any other suggestions will be helpful!!!

procedure Form1_OnShow (Sender: TObject; Action: string);
Var  graphics:Tgraphic;
Var  image:TImage;
var  png: TPNGImage;
var  file_path: string;
begin

      //file path
      file_path:= 'image.png';

      //create the image from code
      image:=TImage.create(frm_main);
      image.Parent:=frm_main.Panel1;
      image.Picture.LoadFromFile(file_path);
      image.name:='image1';
      image.top:=0;
      image.left:=0;
      image.width:=frm_main.Panel1.width;
      image.height:=frm_main.Panel1.height;
      image.autosize:=true;
      image.visible:=true;
      image.enabled:=true;
end;
Post's attachments

Attachment icon Image.rar 14.57 kb, 275 downloads since 2020-10-02