I
I
Ilya2015-01-29 20:17:15
Angular
Ilya, 2015-01-29 20:17:15

How to work with camera in cordova?

Good time. For a week now I have been struggling with the problem of using the camera in a non-native application for android. I am using cordova as api.
Question. How to get a photo from the camera and then get the data url of this photo?
PS I tried to implement it using ngCordova, the camera opens, takes a picture, and then nothing.
Maybe someone has a working code, please share.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Korolev, 2015-01-29
@tenoclock

If we are talking about the plugin https://github.com/apache/cordova-plugin-camera.
The code from the documentation works for me:

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.DATA_URL
});

function onSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

Accordingly, in onSuccess, you can do whatever you want with imageData. There it is substituted with the src parameter to the image.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question