SHARE
TWEET

phonegap

a guest Nov 20th, 2012 1,845 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   <script type="text/javascript" charset="utf-8">
  2.  
  3.     var pictureSource; // picture source
  4.     var destinationType; // sets the format of returned value
  5.  
  6.     // Wait for Cordova to connect with the device
  7.     //
  8.     document.addEventListener("deviceready",onDeviceReady,false);
  9.  
  10.     // Cordova is ready to be used!
  11.     //
  12.     function onDeviceReady() {
  13.         pictureSource=navigator.camera.PictureSourceType;
  14.         destinationType=navigator.camera.DestinationType;
  15.     }
  16.  
  17.     // Called when a photo is successfully retrieved
  18.     //
  19.     function onPhotoDataSuccess(imageData) {
  20.       // Uncomment to view the base64 encoded image data
  21.       // console.log(imageData);
  22.  
  23.       // Get image handle
  24.       //
  25.       var smallImage = document.getElementById('smallImage');
  26.  
  27.       // Unhide image elements
  28.       //
  29.       smallImage.style.display = 'block';
  30.  
  31.       // Show the captured photo
  32.       // The inline CSS rules are used to resize the image
  33.       //
  34.       smallImage.src = "data:image/jpeg;base64," + imageData;
  35.     }
  36.  
  37.     // Called when a photo is successfully retrieved
  38.     //
  39.     function onPhotoURISuccess(imageURI) {
  40.       // Uncomment to view the image file URI
  41.       // console.log(imageURI);
  42.  
  43.       // Get image handle
  44.       //
  45.       var largeImage = document.getElementById('largeImage');
  46.  
  47.       // Unhide image elements
  48.       //
  49.       largeImage.style.display = 'block';
  50.  
  51.       // Show the captured photo
  52.       // The inline CSS rules are used to resize the image
  53.       //
  54.       largeImage.src = imageURI;
  55.     }
  56.  
  57.     // A button will call this function
  58.     //
  59.     function capturePhoto() {
  60.       // Take picture using device camera and retrieve image as base64-encoded string
  61.       navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
  62.         destinationType: destinationType.DATA_URL });
  63.     }
  64.  
  65.     // A button will call this function
  66.     //
  67.     function capturePhotoEdit() {
  68.       // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
  69.       navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
  70.         destinationType: destinationType.DATA_URL });
  71.     }
  72.  
  73.     // A button will call this function
  74.     //
  75.     function getPhoto(source) {
  76.       // Retrieve image file location from specified source
  77.       navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
  78.         destinationType: destinationType.FILE_URI,
  79.         sourceType: source });
  80.     }
  81.  
  82.     // Called if something bad happens.
  83.     //
  84.     function onFail(message) {
  85.       alert('Failed because: ' + message);
  86.     }
  87.  
  88.     </script>
  89.  
  90.     <button onclick="capturePhoto();">Capture Photo</button> <br>
  91.     <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
  92.     <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
  93.     <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
  94.     <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
  95.     <img style="display:none;" id="largeImage" src="" />
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top