Advertisement
Guest User

image from gallery example

a guest
Nov 19th, 2013
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.88 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Capture Photo</title>
  5.  
  6.     <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
  7.     <script type="text/javascript" charset="utf-8">
  8.  
  9.     var pictureSource;   // picture source
  10.     var destinationType; // sets the format of returned value
  11.  
  12.     // Wait for device API libraries to load
  13.     //
  14.     document.addEventListener("deviceready",onDeviceReady,false);
  15.  
  16.     // device APIs are available
  17.     //
  18.     function onDeviceReady() {
  19.         pictureSource=navigator.camera.PictureSourceType;
  20.         destinationType=navigator.camera.DestinationType;
  21.     }
  22.  
  23.    
  24.  
  25.     // Called when a photo is successfully retrieved
  26.     //
  27.     function onPhotoURISuccess(imageURI) {
  28.       // Uncomment to view the image file URI
  29.       // console.log(imageURI);
  30.  
  31.       // Get image handle
  32.       //
  33.       var largeImage = document.getElementById('largeImage');
  34.  
  35.       // Unhide image elements
  36.       //
  37.       largeImage.style.display = 'block';
  38.  
  39.       // Show the captured photo
  40.       // The inline CSS rules are used to resize the image
  41.       //
  42.       largeImage.src = imageURI;
  43.     }
  44.  
  45.    
  46.  
  47.     // A button will call this function
  48.     //
  49.     function getPhoto(source) {
  50.       // Retrieve image file location from specified source
  51.       navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
  52.         destinationType: destinationType.FILE_URI,
  53.         sourceType: source });
  54.     }
  55.  
  56.     // Called if something bad happens.
  57.     //
  58.     function onFail(message) {
  59.       alert('Failed because: ' + message);
  60.     }
  61.  
  62.     </script>
  63.   </head>
  64.   <body>
  65.     <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
  66.     <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
  67.     <img style="display:none;" id="largeImage" src="" />
  68.   </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement