Last active
August 29, 2015 14:21
-
-
Save franfj/e364ba0420a4559145d2 to your computer and use it in GitHub Desktop.
Apache Cordova - Ejemplo API Cámara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Ejemplo API Cámara</title> | |
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
var pictureSource; //Para realizar fotografía o cogerla de imágenes ya en el dispositivo. | |
var destinationType; //Formato que se le dará a la imagen. | |
//Espera que Cordova haya cargado | |
document.addEventListener("deviceready",onDeviceReady,false); | |
function onDeviceReady() { | |
/* | |
* Al asignarle navigator.camera.PictureSourceType elegimos hacer fotografía | |
* Si le asignasemos Camera.PictureSourceType.SAVEDPHOTOALBUM, nos llevaría | |
* a la galería del dispositivo. | |
*/ | |
pictureSource=navigator.camera.PictureSourceType; | |
destinationType=navigator.camera.DestinationType; | |
} | |
function fotoRealizada(imageData) { | |
var imagen = document.getElementById('imagen'); | |
imagen.src = "data:image/jpeg;base64," + imageData; | |
} | |
function hacerFoto() { | |
navigator.camera.getPicture(fotoRealizada, onFail, { quality: 100, | |
destinationType: destinationType.DATA_URL }); | |
} | |
function onFail(message) { | |
alert('Ha ocurrido un error'); | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="hacerFoto();">Hacer foto</button> <br> | |
<img style="max-width:100%; height:auto;" id="imagen"/> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment