Image not scaling when created by code

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hairydalek
Posts: 57
Joined: Sat Feb 01, 2014 8:57 pm

Image not scaling when created by code

Post by hairydalek » Tue Feb 11, 2014 4:03 pm

Hi,
What I am trying to do is add images to a group when someone clicks a button. These images don’t exist in the stack - they are created programatically. Then what happens is that they are rotated and scaled, and this is where the problem arises. Setting the width and height does not work.

Here’s some edited highlights of my code:

Code: Select all

put random( 20 ) - 10 into myAngle
create img in group "cluster" of card "main card"
put the id of it into myImageID
put it into thumbnailImage – doing this as eventually, I’ll be creating a second image in another stack, and I’ll want to reference either at this point

-- storing the ID in an array for future reference
put myImageID into imagesArray[imagesCounter]
put imagesCounter + 1 into imagesCounter

set the loc of thumbnailImage to 300,300
set the showborder of thumbnailImage to false

-- Make the image look like something, using an externally referenced file
put myAppPath & "/label1.png" into myLabelImage
set the text of thumbnailImage to URL ("binfile:" & myLabelImage)

set the visible of thumbnailImage to true
set the loc of thumbnailImage to 300,300
set the showborder of thumbnailImage to false

set the angle of thumbnailImage to 0
set the width of thumbnailImage to the formattedWidth of thumbnailImage 
set the height of thumbnailImage to the formattedHeight of thumbnailImage

-- StickerScale is a variable calculated elsewhere. This ensures that the created image is the right size in the main window (which is a preview)
put 1000 * stickerScale into myWidth
put 644 * stickerScale into myHeight

-- myAngle is a random number created elsewhere
set the angle of thumbnailImage to myAngle

-- These do not work
set the width of thumbnailImage to myWidth
set the height of thumbnailImage to myHeight
This code is applied to a button which creates a new image when clicked. It is a development of the current code I have, which scales and rotates a known image in a stack. However, this limits me to either 1 image to use, or a fixed number, both of which I feel is wrong. I’d like people to use as many as they wish, which is why I am wanting too create images this way. The question is - why is resizing the image not working in this instance?

Klaus
Posts: 14210
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Image not scaling when created by code

Post by Klaus » Tue Feb 11, 2014 4:24 pm

Hi hairydalek,

you should always:
...
set the lockloc of img "your image here" to TRUE
...
when you scale an image smaller/larger than its original dimensions (formattedh/w)
Otherwise the images "snap" back to their original dimensions!
...
put random( 20 ) - 10 into myAngle
create img in group "cluster" of card "main card"
put the id of it into myImageID
put it into thumbnailImage
set the lockloc of thumbnailImage to TRUE
...

Best

Klaus

hairydalek
Posts: 57
Joined: Sat Feb 01, 2014 8:57 pm

Re: Image not scaling when created by code

Post by hairydalek » Tue Feb 11, 2014 4:40 pm

Klaus wrote:Hi hairydalek,

you should always:
...
set the lockloc of img "your image here" to TRUE
...
when you scale an image smaller/larger than its original dimensions (formattedh/w)
Otherwise the images "snap" back to their original dimensions!
...
put random( 20 ) - 10 into myAngle
create img in group "cluster" of card "main card"
put the id of it into myImageID
put it into thumbnailImage
set the lockloc of thumbnailImage to TRUE
...

Best

Klaus
Thank you, Klaus! :-)

Post Reply