How can i create image selection field?

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

SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

How can i create image selection field?

Post by SEAL29 » Fri Oct 02, 2020 3:40 pm

Hi.

How can i create image selection field? So that have one field and i click on it the left or right mouse and i can choose an image from my hard drive and show in field?

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 02, 2020 4:44 pm

Hi.

Do you really want to use a field for this, as opposed to a button? Not that it matters, I was just wondering. Anyway, in either a button or a locked field, place this in the script (pseudo):

Code: Select all

on mouseUp tButton
if tButton = "1" then
   import paint from file "yourFilePathHere" 
   set the rect of last image to "20,20,200,200" --just an example
   set the lockLoc of last image to "true"
   set the loc of last image to whereverYouWish
   else if tButton = 3 then
   --another file path to an image
end mouseUp
Setting the lockLoc is important. Try not doing so and see what happens. A cool thing here is the use of the "last" keyword. This comes in handy in just this sort of case. You can:

Code: Select all

set the name of last img to "whatever"
If you need more help with any of the above, write back...

Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How can i create image selection field?

Post by jmburnod » Fri Oct 02, 2020 4:47 pm

Hi,
You may use imagesource

Code: Select all

set the imageSource of character to {imageID | imageName | imageURL |empty}
Best regards
Jean-Marc
https://alternatic.ch

SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

Re: How can i create image selection field?

Post by SEAL29 » Fri Oct 02, 2020 4:56 pm

Thanks for helping. I get error code in line 9: missing 'end if' command.

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 02, 2020 4:58 pm

Seal29.

That is why I mentioned "(pseudo)".

This was not a working handler.

Do you need a working sample handler to get going? Since you are "live" with me right now, I can do that for you.

Craig

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 02, 2020 5:02 pm

Anyway, here (and this is pseudo again, since things like "yourFilePathHere" are placeholders, not real LiveCode words):

Code: Select all

on mouseUp tButton
   if tButton = "1" then
      import paint from file "yourFilePathHere" 
      set the rect of last image to "20,20,200,200" --just an example
      set the lockLoc of last image to "true"
      set the loc of last image to whereverYouWish
   else if tButton = 3 then
      import paint from file "yourOTHERFilePathHere" 
      set the rect of last image to "20,200,200,400" --just another example
      set the lockLoc of last image to "true"
      set the loc of last image to whereverELSEYouWish
   end if
end mouseUp
Craig
Last edited by dunbarx on Fri Oct 02, 2020 5:06 pm, edited 1 time in total.

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 02, 2020 5:04 pm

Jean-Marc.

An interesting idea, especially since the OP mentioned using a field. But won't this get a bit crowded in a single field, applying imageSources to various chars? I got the feeling that several images were intended to be loaded.

Craig

SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

Re: How can i create image selection field?

Post by SEAL29 » Fri Oct 02, 2020 5:06 pm

dunbarx wrote:
Fri Oct 02, 2020 5:02 pm
Anyway, here:

Code: Select all

on mouseUp tButton
   if tButton = "1" then
      import paint from file "yourFilePathHere" 
      set the rect of last image to "20,20,200,200" --just an example
      set the lockLoc of last image to "true"
      set the loc of last image to whereverYouWish
   else if tButton = 3 then
      import paint from file "yourOTHERFilePathHere" 
      set the rect of last image to "20,200,200,400" --just another example
      set the lockLoc of last image to "true"
      set the loc of last image to whereverELSEYouWish
   end if
end mouseUp
Craig
Thanks for the great help.

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 02, 2020 5:08 pm

SEAL29

Read my edited lastMost post to you, not Jean-Marc, about "pseudo"

Craig

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

Re: How can i create image selection field?

Post by Klaus » Fri Oct 02, 2020 5:31 pm

Hi SEAL29,

welcome to the forum!

If you want to select an image from your HD, do like this:

Code: Select all

on mouseup
  ## Show the system OPEN dialog:
  answer file "Please select an image file." with type "Images|jpg,jpeg,gif,png|" 

  ## IT contains the path of the selected image file
  put it into tFile

  ## Check if user clicked CANCEL
  if the result = "Cancel" then
    ## No need to conttinue in this case!
    exit mouseup
  end if

  ## Now continue like Craig suggested:
  ## Import that image file into your stack:
   import paint from file tFile
   set the rect of last image to "20,20,200,200" --just an example
   ## ...
end mouseup
Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How can i create image selection field?

Post by jmburnod » Fri Oct 02, 2020 5:36 pm

Hi Craig,
Yes, you're probabily right to invite SEAL29 to reconsidere use a fld to display image.
Best
Jean-Marc
https://alternatic.ch

SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

Re: How can i create image selection field?

Post by SEAL29 » Fri Oct 02, 2020 5:51 pm

Klaus wrote:
Fri Oct 02, 2020 5:31 pm
Hi SEAL29,

welcome to the forum!

If you want to select an image from your HD, do like this:

Code: Select all

on mouseup
  ## Show the system OPEN dialog:
  answer file "Please select an image file." with type "Images|jpg,jpeg,gif,png|" 

  ## IT contains the path of the selected image file
  put it into tFile

  ## Check if user clicked CANCEL
  if the result = "Cancel" then
    ## No need to conttinue in this case!
    exit mouseup
  end if

  ## Now continue like Craig suggested:
  ## Import that image file into your stack:
   import paint from file tFile
   set the rect of last image to "20,20,200,200" --just an example
   ## ...
end mouseup
Best
Klaus
Thanks Klaus this is what i was looking for. :D
Million thanks to everyone, you are all very helpful. Thanks.

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 02, 2020 11:20 pm

SEAL29.

I should have guessed that you needed help with securing the pathname. This will all come as you work through stuff and solve problems.

Don't be shy. Ask for details.

Craig

SEAL29
Posts: 63
Joined: Fri Oct 02, 2020 3:32 pm

Re: How can i create image selection field?

Post by SEAL29 » Fri Oct 09, 2020 9:49 pm

It is possible to store only the image reference and not the whole picture (with script). Since there are many images will have a large file size over time?

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

Re: How can i create image selection field?

Post by dunbarx » Fri Oct 09, 2020 11:39 pm

SEAL29.

If you plan on large numbers of images, I would store them in an external file and load as required. This keeps your stack lean. Loading an image takes no time, and external files do not care how large they are. In this way, you only need LC to present the particular image you need.

If you are making a standalone, you must include that file in the standalone settings.

Craig

Post Reply