Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Capture Photo</title>
- <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
- <script type="text/javascript" charset="utf-8">
- var pictureSource; // picture source
- var destinationType; // sets the format of returned value
- // Wait for device API libraries to load
- //
- document.addEventListener("deviceready",onDeviceReady,false);
- // device APIs are available
- //
- function onDeviceReady() {
- pictureSource=navigator.camera.PictureSourceType;
- destinationType=navigator.camera.DestinationType;
- }
- // Called when a photo is successfully retrieved
- //
- function onPhotoURISuccess(imageURI) {
- // Uncomment to view the image file URI
- // console.log(imageURI);
- // Get image handle
- //
- var largeImage = document.getElementById('largeImage');
- // Unhide image elements
- //
- largeImage.style.display = 'block';
- // Show the captured photo
- // The inline CSS rules are used to resize the image
- //
- largeImage.src = imageURI;
- }
- // A button will call this function
- //
- function getPhoto(source) {
- // Retrieve image file location from specified source
- navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
- destinationType: destinationType.FILE_URI,
- sourceType: source });
- }
- // Called if something bad happens.
- //
- function onFail(message) {
- alert('Failed because: ' + message);
- }
- </script>
- </head>
- <body>
- <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
- <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
- <img style="display:none;" id="largeImage" src="" />
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement