dump newbie image questiosn

Jeanne A. E. DeVoto revolution at jaedworks.com
Mon Jun 6 17:49:04 EDT 2005


At 3:37 PM -0400 6/6/2005, Jon wrote:
>This is great if you know in advance that there is enough room to 
>display the image in this way, at this particular scale.  What I 
>wanted was something that automatically displayed the image at the 
>largest resolution possible in "the available space".  That's where 
>the confusion comes in: I need to store the "available space" 
>somewhere in the Image object if I am to perform the computations 
>properly.  Maybe it is just that simple, at least for me.

This should work. (It assumes that when you start, the image is at 
its natural size.)


on scaleImageTo myImage,newRect -- myImage is a short ID
   put item 3 of newRect - item 1 of newRect into newWidth
   put item 4 of newRect - item 2 of newRect into newHeight
   put newWidth/newHeight into newRatio
   put the formattedWidth of image ID myImage/ \
      the formattedHeight of image ID myImage into imageRatio
   lock screen
   -- scale the image to respect its aspect ratio
   if imageRatio = newRatio then
     -- proportions match
     set the height of image ID myImage to newHeight
     set the width of image ID myImage to newWidth
   else if imageRatio > newRatio then
     -- image height is proportionally greater
     set the width of image ID myImage to newWidth
     set the height of image ID myImage to \
        trunc(the width of image ID myImage/imageRatio)
   else -- imageRatio < newRatio
     -- image width is proportionally greater
     set the height of image ID myImage to newHeight
     set the width of image ID myImage to \
        trunc(the height of image ID myImage * imageRatio)
   end if
   set the topLeft of image ID myImage to \
      item 1 of newRect,item 2 of newRect
   -- maintain current size:
   set the lockLoc of image ID myImage to true
   unlock screen
end scaleImageTo
-- 
jeanne a. e. devoto ~ revolution at jaedworks.com
http://www.jaedworks.com


More information about the use-livecode mailing list