Access camera/photos

Is it by any chance possible to access the camera and/or photo library from the phone to be able to use a picture in the game/app?

1 Like

No, not at the moment. The new extension system that will be released soon will allow you to do this and much more.

Ok, that will be awesome! how soon is soon then? what more functionality will be available? is there some information page about this that explains what to expect when its released?

My estimate is within the next few months. The initial tests have gone well, however there are tons of things to consider to make it work good as a whole, so my estimate may vary :slight_smile:
As for an information page/post, it’s a good idea, and we’ve discussed this a bit internally. Soon hopefully!

1 Like

Ok, i just have to wait and see then. :slight_smile:

Any news on this?

The native extension system has been released for all platforms except Linux. You should be able to create an extension that interfaces with the photos/camera roll. To get you started I suggest that you read the manual on native extensions and perhaps look at a couple of existing extensions.

2 Likes

Isn’t there anyone else that is interested in this and have a better knowledge of writing and using extensions? Would really like to se a working Defold Asset where its possible to take control over the camera and take a photo and get the data back to do whatever you like. Also choose a existing photo from library would be an extra feature.

Already possible: https://www.defold.com/community/projects/56615/ (there’s also a separate branch with experimental Android support on the GitHub page)

This would be a new extension. Shouldn’t actually be that hard to implement I think.

Yes, i saw that extension, and that its soon going to work for Android as well is awesome! But how do i use this extension in a game, there is no example of usage of it on the git hub page. dont se it on the “Extension” page eather!? maybe i am blind or just simply useless!!

Getting photo from library is easy!? good, can you do it for me then!? :slight_smile: hehe

Is the extension supposed to open the native camera app and then return the result? or just accessing the camera and i have to make my own camera GUI? How do i view the image in my game?

It’s on the asset page. Almost at the bottom.

Yes there is. It’s there in the GitHub project (in the main folder): https://github.com/defold/extension-camera Open the project and build it for iOS or OSX or switch to the Android branch and build and try on an Android device.

No, the extension will grab frames from the camera and provide them as a Defold buffer. The buffer can then be used in your game and replace the texture on a sprite or used on a quad. There is no UI involved.

1 Like

Perfect, i got it to work a little now, i have a button that opens the camera and shows the stream, then i close it and camera.stop_capture() is triggered. If i then do camera.start_capture(type, quality) a second time i will get a crash and a crashdump file. Any ideas?

Hmm, not off the top of my head no. But the engine should never crash! Would you mind posting the crash dump file here?

Sure.

_crash.zip (2.1 KB)

A new question. I am saving camera.get_frame() data in a global.capturedImageData = {}
This so i from another scene/collection can load the image and view what i just took a picture of, but when i try to do this

resource.set_texture(path, header, global.capturedImageData)

I get this error

The buffer handle is invalid
stack traceback:
[C]: in function ‘set_texture’

I’ve now fixed that start/stop crash, and pushed a new version.

Regarding your question, the resource.set_texture takes a buffer. So when you mention “saving camera.get_frame() data in a global.capturedImageData = {}” it seems slightly wrong. What type is your “global.capturedImageData”?

2 Likes

Thanks for the fix, that was quick! :slight_smile:

So how would you do it? I need to save the image data(get_bytes?) in a data base so other clients can read it and show it in their apps? How do i do that?

You should be able to use buffer.get_bytes() to get the bytes as a string and then perhaps pass those to my png extension to encode them to a png and finally use the io.* functions to save as a file.

Ok, i will try that, but when i have read the saved data, how do i view the image again? any code example of that? do i load it to a sprite or what… and how? :slight_smile: