问题
In Hypercard I can store pictures only on cards. In LiveCode it is possible to store a collection of pictures on the stack level. Is this correct? If yes, how do I load all the pictures in a folder into a stack? And how do I change the read script to only read all the references to pictures into the stack?
回答1:
I think it's not possible to store images in a stack, but not on a card. For storing images on a card, you'll want the import
command. It will place an image on the current (frontmost) card, for example:
answer file "select a picture"
if it <> "" then
import paint from file it
end if
To import several images from one folder, you can use the ask folder
command, and use the defaultfoder
and the files
to get them all:
answer folder "select a folder"
if it <> "" then
set the defaultfolder to it
put the files into myListOfFiles
repeat for each line myFile in myListOfFiles
import paint from file myFile
end repeat
end if
Note that some OSes have hidden files that will show up in the files
. To avoid them, you need to filter them out, for example on Mac OS X:
filter myListOfFiles without ".*"
Another way to avoid unwanted filetypes is to add a qualifier for files you want to include:
if char -4 to -1 of myFile is among the items of ".gif,.jpg,jpeg,.png,.bmp,.tif,tiff" then
import paint from file myFile
end if
回答2:
It's not too hard to store images in a stack without placing them on a card. Do this:
Create a group on any card. Import all your images into it. In the Object menu, choose "Remove group".
This removes the group from the card but does not delete it. The group of images exists on no card but all your images are available. You can reference them normally, use them as icons, copy them to a card later, whatever you need. It's like having an invisible group on a card, only it isn't an object in the hierarchy. It receives no messages and isn't in the object layering.
This is how imported HyperCard stacks store their icon images, by the way. After an HC import you can find an unplaced group named "HC Icons" in the "Place group" menu item in the Object menu. It doesn't exist on any card, but all the imported buttons still show their icons.
回答3:
You could store all the images in a folder in a stack with something like;
answer folder "Select the folder containing your images"
if it <> "" then
set the folder to it
put the files into tFiles
repeat for each line tFile in tFiles
set the uImages[tFile] of this stack to URL("binfile:" & tFile)
end repeat
end if
If you had an image object on your card called 'myImage', and one of the images in the folder was called 'car.png', you could then;
set the text of image "myImage" to the uImages["car.png"] of this stack
To retrieve the list of images stored in the stack, you can reference;
put the customKeys["uImages"] of this stack into tImageList
HTH :)
来源:https://stackoverflow.com/questions/16281017/how-to-store-pictures-in-a-stack