2012-10-26 74 views
3

我正在製作一個應用程序(電暈),將顯示一個文件夾中的圖像。有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") 

但我知道什麼?

希望你能理解我的問題。

- Eirik。

回答

3

你並不遙遠,只要使用連接符 「..」,就像這樣:

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

啊。是的,並不遙遠。謝謝 – Eyrik

-3

您可以通過以下生成圖像:

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。