3

I am making an application (in corona) that will show a image from a folder. There is 50 images in the folder, all name with "number.jpg" (1 to 50)

I am using currently this one to get the number

--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 

How can i make this number, get out the numbered image? Not been using corona, but was thinking somthing like

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

But what do i know?

Hope you understand my question.

-- Eirik.

Eyrik
  • 127
  • 3
  • 13

2 Answers2

3

You're not far off, just use the concatenation operator "..", like so:

myImage = display.newImage("folder/" .. num .. ".jpg")
royi
  • 554
  • 3
  • 9
-3

You can generate an image by following:

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();

Then you can use the outputImage.

Son Nguyen
  • 3,481
  • 4
  • 33
  • 47