Last active
April 1, 2021 04:43
-
-
Save m3l1nd4/cb74163e2c0b3562e9b3cd27170d5c81 to your computer and use it in GitHub Desktop.
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
// Set options for camera | |
function setOptions(srcType) { | |
const options = { | |
quality: 50, | |
destinationType: Camera.DestinationType.DATA_URL, | |
sourceType: srcType, | |
encodingType: Camera.EncodingType.JPEG, | |
mediaType: Camera.MediaType.PICTURE, | |
allowEdit: false, | |
correctOrientation: true, | |
}; | |
return options; | |
} | |
// Take picture with camera | |
function openCamera(selection) { | |
try{ | |
const srcType = Camera.PictureSourceType.CAMERA; | |
const options = setOptions(srcType); | |
navigator.camera.getPicture( | |
function cameraSuccess(imageUrl) { | |
displayImage(imageUrl); | |
}, | |
function cameraError(error) { | |
console.debug("Unable to take picture: " + error, "app"); | |
}, | |
options | |
);} | |
catch { | |
console.error("Something went wrong."); | |
} | |
} | |
function openFilePicker(selection) { | |
... | |
} | |
// Add picture to DOM | |
function displayImage(img) { | |
let image = document.getElementById("imageFile"); | |
image.src = "data:image/jpeg;base64," + img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment