scale image up to fit image view

In Interface Builder, under the attributes for an image view you can scale an image to fit the image view. I’m scaling proportionally. But it seems this scaling only scales an image down to fit the image view. If the image view is larger than the image that setting doesn’t scale the image up.

How can I scale an image up to propotionally fit an image view?

Hi regulus,

as far as I know it’s not possible to access the image size with AppleScript - you may do sth like this using ‘call method’:

	set img to load image imgpath
	
	tell window "main"
		set ivsize to (size of image view "iv")
		set imgsize to (call method "size" of img)
		set hprop to ((item 1 of ivsize) / (item 1 of imgsize))
		set vprop to ((item 2 of ivsize) / (item 2 of imgsize))
		if (vprop < hprop) then
			set theprop to vprop
		else
			set theprop to hprop
		end if
		call method "setSize:" of img with parameter {(item 1 of imgsize) * theprop, (item 2 of imgsize) * theprop}
		set image of image view "iv" to img 
	end tell


Hope that helps …

D.

Hey,

Thanks Dominik!

This was what I was looking for in an earlier post where I asked if it’s possible to adjust the image view to the dimensions of the image to display. I will experiment with your codes and let you know.

archseed :slight_smile:

Hi Dominik! That was perfect. Exactly what I was looking for! Thanks so much.