Guest User

Camera fail test.

a guest
Jul 3rd, 2012
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Capture Photo</title>
  5.  
  6.     <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.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.     var encodingType; // sets the format of returned value
  12.  
  13.     // Wait for PhoneGap to connect with the device
  14.     //
  15.     document.addEventListener("deviceready",onDeviceReady,false);
  16.  
  17.     // PhoneGap is ready to be used!
  18.     //
  19.     function onDeviceReady() {
  20.         console.log("onDeviceReady");
  21.         pictureSource=navigator.camera.PictureSourceType;
  22.         console.log("onDeviceReady1");
  23.        
  24.         destinationType=navigator.camera.DestinationType;
  25.         console.log("onDeviceReady2");
  26.         encodingType=navigator.camera.EncodingType;
  27.        
  28.     }
  29.  
  30.     // Called when a photo is successfully retrieved
  31.     //
  32.     function onPhotoDataSuccess(imageData) {
  33.       // Uncomment to view the base64 encoded image data
  34.       console.log(imageData);
  35.       var re = /\?(\d*)$/;
  36.       imageData=imageData.replace(re, "");
  37.       alert("imageData is "+imageData);
  38.  
  39.       // Get image handle
  40.       //
  41.       var smallImage = document.getElementById('smallImage');
  42.  
  43.       // Unhide image elements
  44.       //
  45.       smallImage.style.display = 'block';
  46.  
  47.       // Show the captured photo
  48.       // The inline CSS rules are used to resize the image
  49.       //
  50.       smallImage.src = "data:image/jpeg;base64," + imageData;
  51.     }
  52.  
  53.     // Called when a photo is successfully retrieved
  54.     //
  55.     function onPhotoURISuccess(imageURI) {
  56.       // Uncomment to view the image file URI
  57.       console.log(imageURI);
  58.       // alert("uri is "+imageURI);
  59.       var re = /\?(\d*)$/;
  60.       imageURI=imageURI.replace(re, "");
  61.       alert("imageURI is "+imageURI);
  62.  
  63.       // Get image handle
  64.       //
  65.       var largeImage = document.getElementById('largeImage');
  66.  
  67.       // Unhide image elements
  68.       //
  69.       largeImage.style.display = 'block';
  70.  
  71.       // Show the captured photo
  72.       // The inline CSS rules are used to resize the image
  73.       //
  74.       largeImage.src = imageURI;
  75.     }
  76.  
  77.     // A button will call this function
  78.     //
  79.     function capturePhoto() {
  80.       // Take picture using device camera and retrieve image as base64-encoded string
  81.       navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100, targetWidth: -1, targetHeight: -1, encodingType:encodingType.PNG });
  82.     }
  83.  
  84.     // A button will call this function
  85.     //
  86.     function capturePhotoEdit() {
  87.       // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
  88.       navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100, allowEdit: true, targetWidth: -1, targetHeight: -1 ,encodingType:encodingType.PNG, });
  89.     }
  90.  
  91.     // A button will call this function
  92.     //
  93.     function getPhoto(source) {
  94.       // Retrieve image file location from specified source
  95.       navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100, targetWidth: -1, targetHeight: -1 ,
  96.         destinationType: destinationType.FILE_URI,encodingType:PNG,
  97.         sourceType: source });
  98.     }
  99.  
  100.     // Called if something bad happens.
  101.     //
  102.     function onFail(message) {
  103.       alert('Failed because: ' + message);
  104.     }
  105.  
  106.     </script>
  107.   </head>
  108.   <body>
  109.     <button onclick="capturePhoto();">Capture Photo</button> <br>
  110.     <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
  111.     <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
  112.     <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
  113.     <img style="width:60px;height:60px;" id="smallImage" src="a.png" />
  114.     <img style="" id="largeImage" src="a.png" />
  115.   </body>
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment