HartleySan
HartleySan

Reputation: 7830

How to take in-app photo with PhoneGap?

I've noticed that certain apps (e.g., Colorfy) allow you to take a photo within the app that can then be further edited. Is there any way to do that with a PhoneGap app?

All the PhoneGap examples I've ever seen have you accessing navigator.camera.getPicture, which is fine, except that it requires you to jump over to the camera app to take the picture, confirm the picture you just took, etc. I'd really love to be able to skip all of that and take the picture directly in the app, but I'm not sure if it's possible.

If it is possible, please let me know how. Thanks.

Upvotes: 0

Views: 87

Answers (1)

atulkhatri
atulkhatri

Reputation: 11343

You will have to create a custom Plugin for this to work.

This will be the flow:

• Call the PhoneGap plugin from webpage

• Plugin will open the camera view

• After image has clicked it is then encoded in base-64

• Send this base-64 encoded image to webpage using Plugin callback.

Below code can be used for encoding the image:

UIImage* image= <Image received from the camera>;
NSString *base64EncodedImage = [Base64 encode:UIImageJPEGRepresentation(image, 0.5)];

Edit:

A few sample plugins:

https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview

https://github.com/donaldp24/CanvasCameraPlugin

Upvotes: 1

Related Questions