Page 1 of 1

Scaling an image to fit the group dimensions

Posted: Sun Jan 06, 2013 4:10 pm
by rleiman
Hi Everyone,

Can you show me the coding needed to scale an image to fit the dimensions of a group?

I'm not concerned with aspect ratio but would like the image to fill the entire space of the group.

Thanks.

Re: Scaling an image to fit the group dimensions

Posted: Sun Jan 06, 2013 5:27 pm
by dunbarx
Sure.

set the rect of image "yourImage" to the rect of group "yourGroup"

Craig Newman

Re: Scaling an image to fit the group dimensions

Posted: Sun Jan 06, 2013 5:52 pm
by rleiman
Hi Carig,

I tried it but the image is not filling the entire group.

It fills the width but not the height.

I used this coding:

Code: Select all

on preOpenCard
   put screenrect() into theScreenSize
   
   set the width of group "big ben group" to word 1 of item 3 of the field "theScreenSize" 
   set the height of group "big ben group" to word 1 of item 4 of the field "theScreenSize" 
   set the rect of image "big-ben.png" to the rect of group "big ben group"
end preOpenCard

Re: Scaling an image to fit the group dimensions

Posted: Sun Jan 06, 2013 6:08 pm
by Dixie
set the margins of the image and the group to 0

Dixie

Re: Scaling an image to fit the group dimensions

Posted: Sun Jan 06, 2013 6:46 pm
by dunbarx
Aha.

Dixie's point may be your problem. Newly created objects (other than fields) have default margins set to four pixels. This may, depending on the construction of your group, cause the edges of the two objects to visually misalign. On the other hand, again depending on the group, you may use this property to your advantage, the other method being that you control the image rect itself.

Craig Newman

Re: Scaling an image to fit the group dimensions

Posted: Sun Jan 06, 2013 6:51 pm
by rleiman
Thanks everyone for the helpful replies. :D