Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread Stumped: Image original size?
Sat, Jul 12 2014 8:08 PMPermanent Link

Almanac

Avatar

Okay, I've put in my two hours of searching forums and playing with TImage autosize proportional and stretch parameters but no luck in extracting the image's original dimensions. I've put the parameters in separate buttons so I can change them after load, but still no luck.

All I want are the values of image's original size at runtime, so I can calculate what the stretch factor is, and

I've read a little bit about Exif decoding and using external js to extract it, but it seems like overkill when the control has to know what it is - after all, it's resizing it.

Truly stumped,
Alister.
Sun, Jul 13 2014 9:09 AMPermanent Link

Uli Becker

Almanac,

you can get the original image size with "ImageWidth" and "ImageHeight".

provided that these properties are "false":

Proportional
Stretch

Uli
Sun, Jul 13 2014 10:52 AMPermanent Link

Almanac

Avatar

Sadly no, this does not work at runtime. Only at design time can I get the image size, and only by turning autosize to false and back to true (double-clicking twice) - for each new image I load. Same in I.E. and Firefox with the latest java installed (just in case).

My project files are attached. I only have a Timage on a Form with the buttons for turning the properties on and off. I even set the form to 9000x6000 to allow the image to expand.

For the time being, I will enter the size manually.
Alister.



Attachments: zip.7z
Sun, Jul 13 2014 12:52 PMPermanent Link

Uli Becker

I tried it in the IDE and it works regardless of the Autosize setting.

You attached the *.js and *.html files, not your project.

Uli
Mon, Jul 14 2014 7:08 AMPermanent Link

Mark Brooks

Slikware

Avatar

Guys,

Here is a snippet of code that I use to scale thumbnails. You'll see that it calculates natural width and height (NW and NH) in the OnLoad event. This is required to shrink the image down proportionality. You need to have Stretch set to False when you set the image, the set it to True at the end of OnLoad (if your app requires).

Hope it helps.

Mark

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

procedure TfrmGallery.TrapThumbnailLoad(Sender: TObject);
var
 W,H,NW,NH: double;
begin

 // Get natural dimensions

 NW := TImage(Sender).ImageWidth;
 NH := TImage(Sender).ImageHeight;

 // Calc size to fit in real estate

 W := pnlImages.ClientWidth - 16 - 16;
 H := (W * NH) / NW;
 if H > 200 then
   begin
     H := 200;
     W := (H * NW) / NH;
   end;

 // Adjust

 TImage(Sender).Width := Round(W);
 TImage(Sender).Height := Round(H);

 // Centralise

 if TImage(Sender).Height = 200 then
   TImage(Sender).Left := TImage(Sender).Left + (200 - TImage(Sender).Width) div 2
 else
   TImage(Sender).Top := TImage(Sender).Top + (200 - TImage(Sender).Height) div 2;

 // Set stretch back to True (was False when setting image)

 TImage(Sender).Stretch := True;
end;
Mon, Jul 14 2014 4:52 PMPermanent Link

Uli Becker

Mark,

thanks for sharing your code.

Uli
Sun, Jul 20 2014 10:12 PMPermanent Link

Almanac

Avatar

Mark, many thanks for your code snippet.

It would *never* had occurred to me to use
"NW = TImage(Sender).ImageWidth;" in an onload event.

I've never seen that style of accessing properties before. The classic Image1.Width  and Image1.Stretch etc methods were all I knew.

Works marvelously now.
Much appreciated,
Alister.
Fri, Sep 26 2014 7:36 PMPermanent Link

Almanac

Avatar

Just to put a proper end this thread... your recommendations have been included in my web app. I've zipped up the project and posted it in the demos section for all to use:
http://www.elevatesoft.com/forums?action=view&category=ewb&id=ewb_demos&page=1&msg=162#162

I really appreciate everyone's help and pointers over the past few months!
Alister.
Sat, Sep 27 2014 10:32 AMPermanent Link

Mark Brooks

Slikware

Avatar

>> I really appreciate everyone's help and pointers over the past few months!

Great stuff - glad you got it all working the way you wanted!
Image