1

在 Hypercard 中,我只能将图片存储在卡片上。在 LiveCode 中,可以在堆栈级别存储一组图片。这个对吗?如果是,如何将文件夹中的所有图片加载到堆栈中?以及如何将读取脚本更改为仅将所有对图片的引用读取到堆栈中?

4

3 回答 3

3

在不将图像放在卡片上的情况下将图像存储在堆栈中并不难。做这个:

在任何卡上创建一个组。将所有图像导入其中。在“对象”菜单中,选择“删除组”。

这会将组从卡中删除,但不会将其删除。该组图像不存在于卡上,但您的所有图像都可用。您可以正常引用它们,将它们用作图标,稍后将它们复制到卡片中,无论您需要什么。这就像在卡片上有一个不可见的组,只是它不是层次结构中的对象。它不接收任何消息并且不在对象分层中。

顺便说一句,这就是导入的 HyperCard 堆栈存储其图标图像的方式。HC 导入后,您可以在 Object 菜单的“Place group”菜单项中找到一个名为“HC Icons”的未放置组。它在任何卡上都不存在,但所有导入的按钮仍显示其图标。

于 2013-05-04T17:38:07.970 回答
3

我认为不可能将图像存储在堆栈中,但不能存储在卡上。要将图像存储在卡上,您将需要该import命令。它将在当前(最前面的)卡片上放置一个图像,例如:

answer file "select a picture"
if it <> "" then
   import paint from file it
end if

要从一个文件夹中导入多个图像,您可以使用ask folder命令,然后使用the defaultfoderandthe files来获取它们:

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

请注意,某些操作系统具有隐藏文件,这些文件将显示在the files. 为了避免它们,您需要将它们过滤掉,例如在 Mac OS X 上:

filter myListOfFiles without ".*"

避免不需要的文件类型的另一种方法是为要包含的文件添加限定符:

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
于 2013-04-29T15:00:25.067 回答
1

您可以将所有图像存储在堆栈中的文件夹中,例如:

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

如果您的卡上有一个名为“myImage”的图像对象,并且文件夹中的其中一个图像名为“car.png”,那么您可以;

set the text of image "myImage" to the uImages["car.png"] of this stack

要检索存储在堆栈中的图像列表,您可以参考;

put the customKeys["uImages"] of this stack into tImageList

HTH :)

于 2013-04-29T15:22:55.103 回答