|Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread|
|Messages 1 to 9 of 9 total|
|Stumped: Image original size?|
|Sat, Jul 12 2014 8:08 PM||Permanent Link|
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.
|Sun, Jul 13 2014 9:09 AM||Permanent Link|
you can get the original image size with "ImageWidth" and "ImageHeight".
provided that these properties are "false":
|Sun, Jul 13 2014 10:52 AM||Permanent Link|
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.
|Sun, Jul 13 2014 12:52 PM||Permanent Link|
I tried it in the IDE and it works regardless of the Autosize setting.
You attached the *.js and *.html files, not your project.
|Mon, Jul 14 2014 7:08 AM||Permanent Link|
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.
procedure TfrmGallery.TrapThumbnailLoad(Sender: TObject);
// 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
H := 200;
W := (H * NW) / NH;
TImage(Sender).Width := Round(W);
TImage(Sender).Height := Round(H);
if TImage(Sender).Height = 200 then
TImage(Sender).Left := TImage(Sender).Left + (200 - TImage(Sender).Width) div 2
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;
|Mon, Jul 14 2014 4:52 PM||Permanent Link|
thanks for sharing your code.
|Sun, Jul 20 2014 10:12 PM||Permanent Link|
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.
|Fri, Sep 26 2014 7:36 PM||Permanent Link|
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:
I really appreciate everyone's help and pointers over the past few months!
|Sat, Sep 27 2014 10:32 AM||Permanent Link|
>> 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!