How to display a captured image?

Hello,

 I am capturing an image into the system.DocumentsDirectory then I am trying to display it by using:

local capturedImage = display.newImageRect( sceneGroup, "mycat.png", system.DocumentsDirectory, 401, 868 ) capturedImage.x, capturedImage.y = display.contentWidth \* 0.25, display.contentHeight \* 0.25

but I get the error:

ERROR: C:\Users\aaa\Documents\Corona Projects\capture\_image\scene1.lua:44: display.newImageRect() bad argument #1: filename or image sheet expected, but got nil 20:01:41.973 ERROR: Runtime error 20:01:41.973 C:\Users\aaa\Documents\Corona Projects\capture\_image\scene1.lua:45: attempt to index local 'capturedImage' (a nil value)

Capturing the image works because I can see the image in the Sandbox Documents folder. 

I spent a couple of days trying to figure it out but I couldn’t. Any help is highly appreciated.

I have attached a sample project that shows the problem.

Thanks.

You forgot to attach the sample project.

If you are directly capturing some location and you then want to show it, you could alternatively just use https://docs.coronalabs.com/api/library/display/capture.html

Sorry. I thought I did attach it. 

Hopefully file now attached.

Capturing and saving works. It’s retrieving the captured image that doesn’t work.

It’s crashing because of  sceneGroup.

sceneGroup is local to each of your scene functions, but your showImage function is outside of them and thus it doesn’t have a reference to it. You have several ways to fix this. You could create a display group outside of the scene functions (definitely the easiest and the cleanest, especially if you are using groups).

Alternatively you could create a variable called “groupRef” outside of the scene functions (e.g. on row 10 or so) and then assign groupRef = sceneGroup on row 33 and then just pass groupRef as an argument into your showImage function instead of sceneGroup.

Thanks @XeduR

Well spotted. 

You forgot to attach the sample project.

If you are directly capturing some location and you then want to show it, you could alternatively just use https://docs.coronalabs.com/api/library/display/capture.html

Sorry. I thought I did attach it. 

Hopefully file now attached.

Capturing and saving works. It’s retrieving the captured image that doesn’t work.

It’s crashing because of  sceneGroup.

sceneGroup is local to each of your scene functions, but your showImage function is outside of them and thus it doesn’t have a reference to it. You have several ways to fix this. You could create a display group outside of the scene functions (definitely the easiest and the cleanest, especially if you are using groups).

Alternatively you could create a variable called “groupRef” outside of the scene functions (e.g. on row 10 or so) and then assign groupRef = sceneGroup on row 33 and then just pass groupRef as an argument into your showImage function instead of sceneGroup.

Thanks @XeduR

Well spotted.