Page 1 of 2

How can i create image selection field?

Posted: Fri Oct 02, 2020 3:40 pm
by SEAL29
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?

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 4:44 pm
by dunbarx
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

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 4:47 pm
by jmburnod
Hi,
You may use imagesource

Code: Select all

set the imageSource of character to {imageID | imageName | imageURL |empty}
Best regards
Jean-Marc

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 4:56 pm
by SEAL29
Thanks for helping. I get error code in line 9: missing 'end if' command.

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 4:58 pm
by dunbarx
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

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:02 pm
by dunbarx
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

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:04 pm
by dunbarx
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

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:06 pm
by SEAL29
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.

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:08 pm
by dunbarx
SEAL29

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

Craig

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:31 pm
by Klaus
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

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:36 pm
by jmburnod
Hi Craig,
Yes, you're probabily right to invite SEAL29 to reconsidere use a fld to display image.
Best
Jean-Marc

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 5:51 pm
by SEAL29
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.

Re: How can i create image selection field?

Posted: Fri Oct 02, 2020 11:20 pm
by dunbarx
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

Re: How can i create image selection field?

Posted: Fri Oct 09, 2020 9:49 pm
by SEAL29
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?

Re: How can i create image selection field?

Posted: Fri Oct 09, 2020 11:39 pm
by dunbarx
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