A Few Questions about "Import Paint"

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
NullSet
Posts: 13
Joined: Fri Dec 28, 2018 12:39 am

A Few Questions about "Import Paint"

Post by NullSet » Tue Mar 12, 2019 5:27 pm

Regarding:

Code: Select all

 answer file "Select a an image:"
 import paint from file it
This seems to create a new image object. According to the dictionary, "The import command places the data in the stack file itself."

Three questions:

1 - Where and how is the image data stored? Is it a customKey? Is it saved in the image object, or somewhere else?

2 - After the new image object is created, how do I reference it in the script, to manipulate its properties?

3 - I can resize the image proportionally by grabbing and dragging a corner while holding down the shift key. Is there an easy way to resize the image proportionally by script? (I could get the height and width of the image, do the necessary arithmetic and set new height and width, so the proportions are preserved. Is there an easier way?)

Thanks!

Tim

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

Re: A Few Questions about "Import Paint"

Post by Klaus » Tue Mar 12, 2019 6:03 pm

Hi Tim,
1 - Where and how is the image data stored? Is it a customKey? Is it saved in the image object, or somewhere else?
in the image object.
2 - After the new image object is created, how do I reference it in the script, to manipulate its properties?
That image is the LATEST object on the card, so you can refer to it:
...
put the loc of LAST IMAGE into tImageLoc
...
right after you have created it.
3 - I can resize the image proportionally by grabbing and dragging a corner while holding down the shift key. Is there an easy way to resize the image proportionally by script? (I could get the height and width of the image, do the necessary arithmetic and set new height and width, so the proportions are preserved. Is there an easier way?
The ONLY way to do this is to do the rule of three with:
the formattedwidth of img X
and
the formattedheight of img X
! 8)

Best

Klaus

P.S.
Please check these stacks for more basics of LC:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: A Few Questions about "Import Paint"

Post by dunbarx » Tue Mar 12, 2019 6:08 pm

Hi.

1- Others will likely provide better answers than I.

2- You can always:

Code: Select all

on mouseUp
   answer file "Select a an image:"
   import paint from file it
   set the name of last img to "yourNameHere"
end mouseUp
3- You can do anything you want under script control. Know that it is important to set the "lockLoc" of the image, or its size will not stick:

Code: Select all

on mouseUp
   answer file "Select a an image:"
   import paint from file it
   set the name of last img to "yourNameHere"
   set the width of img "yourNameHere" to 100
   set the height of img "yourNameHere" to 100
   set the lockLoc of img "yourNameHere" to "true"
end mouseUp
It seems you understand how to set the size and loc of the image proportionately to the size of the card. This just takes a few more lines of code, no?

Craig Newman

Post Reply