--> Knowing Resolution Image File by Delphi | Delphi Tips Trick

For Newbie

Tuesday, 15 November 2011

Knowing Resolution Image File by Delphi

| Tuesday, 15 November 2011


The trick to read the resolution of image files of type.

Declaration procedure:
ResolusiGambar procedure (filename: String; var w, h: Integer);
var
   pic: TPicture;
begin
   pic: = TPicture.Create;
   try
     pic.LoadFromFile (filename);
     if pic.Graphic <> nil then
     begin
       with TBitmap.Create do
       begin
         try
           Assign (pic.Graphic);
           w: = Width;
           h: = Height;
         finally
           free;
         end;
       end;
     end;
   finally
     pic.Free
   end;
end;

parameters:
- Filename: the file location.
- W, h: is a variable that stores the image information Width and Height.

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
   w, h: Integer;
begin
   Resolusi ('C: \ Windows \ Santa Fe Stucco.bmp', w, h);
   Label2.Caption: = 'Resolution is:' + IntToStr (w) + 'x' + IntToStr (h);
end;

Example implementations # 2 (using TOpenDialog, TImage):
procedure TForm1.Button1Click (Sender: TObject);
var
   F: String;
   w, h: Integer;
begin
   if OpenDialog1.Execute then
   begin
     try
       F: = OpenDialog1.FileName;
       Image1.Picture.LoadFromFile (F);
       Resolusi (F, w, h);
       Label2.Caption: = IntToStr (w) + 'x' + IntToStr (h);
     except
       ShowMessage ('Unable to load image');
     end;
   end;
end;

Related Posts

No comments: