Recent

Author Topic: [Solved] Keeping ratio aspect for a picture in a TImage component  (Read 4384 times)

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Hello

I know something is wrong, because it is not working!  ;D
Code: [Select]
ubilleder.pas(91,23) Error: No member is provided to access property

but I can't find where
Code: [Select]
procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
  tal: extended;
  largeur, hauteur: integer;
begin
  if not(DBGrid1.DataSource.DataSet.Fields[1].Value = NULL) then
  Image1.Picture.LoadFromFile(DBGrid1.DataSource.DataSet.Fields[1].Value);
  If Image1.Picture.Width > Image1.Picture.Height then
  tal:= Image1.Picture.Width/Image1.Width
  else tal:= Image1.Picture.Height/Image1.Width;
  largeur := Round (Image1.Picture.Width * tal);
  hauteur:= Round (Image1.Picture.Height * tal);
  Image1.Picture.Width:= largeur;
  Image1.Picture.Height:= hauteur;
end;                       

Is it because I try to access the size of the picture, after the picture is loaded?

Best Regards
Jean-Christophe
« Last Edit: August 21, 2014, 11:06:56 am by jeanchristophe »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Keeping ratio aspect for a picture in a TImage component
« Reply #1 on: August 20, 2014, 07:48:41 pm »
How about setting the stretch to true and proportional to true and resize it to what ever the max space is?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: Keeping ratio aspect for a picture in a TImage component
« Reply #2 on: August 20, 2014, 08:03:22 pm »
Thank you for your answer taazz!

Both stretch and proportional are true.
As I mentioned in my post, this is the resizing which is giving me problem.

Best Regards
Jean-Christophe   

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Keeping ratio aspect for a picture in a TImage component
« Reply #3 on: August 20, 2014, 08:06:13 pm »
set the image.align to alclient. The proportional resizing will be done automatically for you.
Set Center to true too to allow the picture to be centered in the space the image1 occupies.
Also you could look the resizing on Timage when proportional property is true.
« Last Edit: August 20, 2014, 08:09:21 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: Keeping ratio aspect for a picture in a TImage component
« Reply #4 on: August 20, 2014, 09:10:25 pm »
Thank you again taazz

I take a look on TImage when resizing is true and get back later.

Have a nice evening
Jean-Christophe

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: Keeping ratio aspect for a picture in a TImage component
« Reply #5 on: August 21, 2014, 11:06:39 am »
I find out!

The only value from the TImage component to be changed is the proportional.
Code: [Select]
If Image1.Proportional = false then Image1.Proportional := True;

Code: [Select]
Image1.Align:= alnone;
Image1.AutoSize= false;
Image1.Center = false;
Image1.Stretch = false;

That's it!  :D

 

TinyPortal © 2005-2018