Creating an image

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Creating an image

Post by exheusden » Thu Oct 22, 2009 12:00 pm

I'm trying to create an image on a card. The image is one selected earlier by the user; its pathname is in the variable originalFile.

Here's the script that I would hope would create the image:
create invisible image "Original label"
put it into originalImage
set the width of originalImage to 230
set the height of originalImage to 230
set the location of originalImage to 772,319
set the fileName of originalImage to originalFile
set the visible of originalImage to true
After running this, however, the size and location of the image is that of the selected file "originalFile"; in other words, the "set the width" and "set the height" commands have had no effect (this can be seen not only in the image itself, but also in the Size & Position property panel for the image). The "set the location" and "set the fileName" commands are correctly executed.

What am I doing wrong?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 22, 2009 1:29 pm

exheusden,

This should work:

Code: Select all

create invisible image "Original label"
put it into originalImage
set the fileName of originalImage to originalFile
set the width of originalImage to 230
set the height of originalImage to 230
set the location of originalImage to 772,319
set the lockLoc of originalImage to true
set the visible of originalImage to true
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Post by exheusden » Thu Oct 22, 2009 1:54 pm

Thank you!

So, if I understand it correctly, it's the sequence of the set commands that is the key. I've tried the code by just moving the set fileName command to the top (as in your suggestion) and without the set lockLoc command (in my case, unnecessary, but I can see why you'd use it), and it works. So what is so special about the sequence of set commands? Is this documented?

Edit: Oops, spoke too soon. Looks as if the lockLoc is required. When I move to the next card and back again, the image is resized without it.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 22, 2009 2:03 pm

You got it :-)

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Oct 22, 2009 2:03 pm

exheusden,

the problem is that if you load an image by setting the filename the image adjusts its size to the size of the referenced image except if you set the lockloc to true as Mark did.
The only difference in the order of commands is that you load the filename image first and then set the width and size, so in that case the lockloc is not necessary.
regards
Bernd

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Post by exheusden » Thu Oct 22, 2009 2:09 pm

Okay, understand the logic. Thanks to the two of you.

Post Reply