Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to display a captured image?
Started by ammar71 Aug 02 2019 11:11 AM

4 replies to this topic
newimagerect documentsdirectory

Best Answer XeduR @Spyric , 03 August 2019 - 01:56 AM

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.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 822 posts
  • Corona SDK

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



[TOPIC: post.html]
#3

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

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.

 

Attached Files



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 822 posts
  • Corona SDK

  Best Answer

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.


  • ammar71 likes this

[TOPIC: post.html]
#5

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

Thanks @XeduR

 

Well spotted. 

 

 




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: newimagerect, documentsdirectory