Thanks Dmitry,
Exploring your suggestion, I ended up with a procedure (on click of the TImage) but there are various cases to consider :
- image is in landscape or portrait mode
- image is larger or smaller to screen resolution
I known this is not MVD but Delphi, but this is what I came up with. This work fine in my application but would you mind giving your advises, I'm sure I overlooked some details (I use TImage because all major image formats are already supported and I don't need to convert)
NOTE : the form that displays the image is created on click and destroyed on Close and images are displayed with a ratio of 0.9 to their original size
//-06-DISPLAYING IMAGE FULL SIZE ON CLICK
procedure TfrmAssetEdit.Image3Click(Sender: TObject);
var
F_Im_View : TfrmImageView;
ImageH, ImageW, ScreenH, ScreenW : Integer;
RatioI : Double;
begin
try
F_Im_View := TfrmImageView.Create(nil);
//Screen Dimensions
ScreenH := Screen.Height;
ScreenW := Screen.Width;
//Image Dimensions
ImageH := Image3.Picture.Height;
ImageW := Image3.Picture.Width;
//Image Ration
RatioI := ImageW / ImageH;
if RatioI > 1 then //Image is in landscape mode
begin
if (ImageW <= ScreenW) AND (ImageH <= ScreenH)then
begin
F_Im_View.Image1.Picture := Image3.Picture;
F_Im_View.ClientWidth := Round(ImageW * 0.9);
F_Im_View.Image1.Width := Round(ImageW * 0.9);
F_Im_View.ClientHeight := Round(ImageH * 0.9);
F_Im_View.Image1.Height := Round(ImageH * 0.9);
F_Im_View.Image1.Proportional := True;
F_Im_View.ShowModal;
end
else
begin
F_Im_View.Image1.Picture := Image3.Picture;
F_Im_View.ClientHeight := Round(ScreenH * 0.9);
F_Im_View.Image1.Height := Round(ScreenH * 0.9);
F_Im_View.ClientWidth := Round(ImageW * ScreenH * 0.9 / ImageH);
F_Im_View.Image1.Width := Round(ImageW * ScreenH * 0.9 / ImageH);
F_Im_View.Image1.Proportional := True;
F_Im_View.ShowModal;
end;
end
else if RatioI <= 1 then //Image is in Portait mode
if (ImageW <= ScreenW) AND (ImageH <= ScreenH)then
begin
F_Im_View.Image1.Picture := Image3.Picture;
F_Im_View.ClientWidth := Round(ImageW * 0.9);
F_Im_View.Image1.Width := Round(ImageW * 0.9);
F_Im_View.ClientHeight := Round(ImageH * 0.9);
F_Im_View.Image1.Height := Round(ImageH * 0.9);
F_Im_View.Image1.Proportional := True;
F_Im_View.ShowModal;
end
else
begin
F_Im_View.Image1.Picture := Image3.Picture;
F_Im_View.ClientHeight := Round(ScreenH * 0.9);
F_Im_View.Image1.Height := Round(ScreenH * 0.9);
F_Im_View.ClientWidth := Round((ImageW * ScreenH * 0.9) / ImageH);
F_Im_View.Image1.Width := Round((ImageW * ScreenH * 0.9) / ImageH);
F_Im_View.Image1.Proportional := True;
F_Im_View.ShowModal;
end;
finally
F_Im_View.Free;
end;
end;
Cheers
Mathias
I'm a very good housekeeper !
Each time I get a divorce, I keep the house
Zaza Gabor