How do I import a image file

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
tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

How do I import a image file

Post by tanjc » Thu May 16, 2013 2:39 pm

Hi,

I have some livecode experts could help me with the following problem.

I am trying to import images using the following script, the result display garbage.
I believed the problem lies in the field "text". How can I overcome this problem.

on mouseUp
answer file "Select a file" with filter "Web Graphics,*.jpg;*.gif;*.png"
if it <> "" then
put it into theFilePath
--don't forgett the brackets!
put URL ("file:" & theFilePath) into field "text"
else
--no file was selected, or cancel was pressed
beep
end if
end mouseUp

Thanks for your help.

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

Re: How do I import a image file

Post by Klaus » Thu May 16, 2013 3:05 pm

Hi tanjc,

well, FIELDS are supposed to display TEXT and IMAGES to display images :-)

You CAN of course display in a field, but not this way, it will requre that the
image is already IN the stack.

Do this to import the user selected image into the stack:

Code: Select all

on mouseUp
  answer file "Select a file" with filter "Web Graphics,*.jpg;*.gif;*.png"
  put it into theFilePath
  
  ## I always check for the NEGATIVE side of things,
  ## so I can avoid long and maybe nested IF...THEN clauses :-)
  if theFilePath = EMPTY then
    beep
    exit mouseup
  end if
  
  ## Import image into stack as a new image:
  import paint from file theFilePath
  ## Done :-)
end mouseUp
Best

Klaus

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How do I import a image file

Post by Dixie » Thu May 16, 2013 3:06 pm

Hi...

try something like this...

Code: Select all

on mouseUp
   answer file ""
   if it is not empty then set the filename of image 1 to it
end mouseUp
Notice the difference, with 'set the filename'

Dixie

tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

Re: How do I import a image file

Post by tanjc » Sun May 19, 2013 7:32 am

Thanks very much to Klaus and Dixie. The codes you provide are very useful, exactly what I am looking for.
I am new to LiveCode and have a lot to learn from you guys.

Post Reply