【问题标题】:Displaying image from random number从随机数显示图像
【发布时间】:2012-10-26 02:33:44
【问题描述】:

我正在制作一个应用程序(在电晕中),它将显示文件夹中的图像。文件夹里有50张图片,名字都是“number.jpg”(1到50)

我目前正在使用这个来获取号码

--populating table with 50 numbers (1-50)
for i =1,50 do
numbers[i] = i 
end

--loop to generate 1 random number
for i = 1, 1 do
-- select random position from the table
local pos = math.random(1,#numbers)
    local num = numbers[pos]
    print(num)
    --remove the number from table once it is selected
table.remove (numbers,table.indexOf(numbers, num))
end 

我怎样才能使这个数字,得到编号的图像? 没有使用电晕,但正在考虑类似的事情

myImage = display.newImage("/folder/", num, ".jpg")

但我知道什么?

希望你能理解我的问题。

-- 埃里克。

【问题讨论】:

    标签: iphone image coronasdk displayobject


    【解决方案1】:

    你不远了,只需使用连接运算符“..”,如下所示:

    myImage = display.newImage("folder/" .. num .. ".jpg")
    

    【讨论】:

    • 啊。是的,不远了。谢谢
    【解决方案2】:

    您可以通过以下方式生成图像:

    UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    numberLabel.text = @"[Your random number]";
    
    // save label as image
    UIGraphicsBeginImageContext([numberLabel bounds].size);
    [[numberLabel layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    然后就可以使用outputImage了。

    【讨论】:

      猜你喜欢
      • 2010-11-08
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      相关资源
      最近更新 更多