Iphone 从随机数显示图像
我正在制作一个应用程序(在corona中),它将显示文件夹中的图像。文件夹中有50个图像,所有名称都带有“number.jpg”(1到50) 我目前正在使用这个来获取号码Iphone 从随机数显示图像,iphone,image,coronasdk,displayobject,Iphone,Image,Coronasdk,Displayobject,我正在制作一个应用程序(在corona中),它将显示文件夹中的图像。文件夹中有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
--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")
但我知道什么
希望你能理解我的问题
--Eirik.您可以通过以下方式生成图像:
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。不远,只需使用串联运算符“.”,如下所示:
myImage = display.newImage("folder/" .. num .. ".jpg")
啊。是的,不远。谢谢