Advertisement
Guest User

Untitled

a guest
Aug 10th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Capture Photo</title>
  5. <script src="jquery-1.6.2.js"></script>
  6. <script src="jquery.mobile-1.0a4.1.js"></script>
  7. <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0rc2.js"></script>
  8. <script type="text/javascript" charset="utf-8">
  9.  
  10. var pictureSource; // picture source
  11. var destinationType; // 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. pictureSource=navigator.camera.PictureSourceType;
  21. destinationType=navigator.camera.DestinationType;
  22. }
  23.  
  24. // Called when a photo is successfully retrieved
  25. //
  26. function onPhotoDataSuccess(imageData) {
  27. // Uncomment to view the base64 encoded image data
  28. console.log(imageData);
  29.  
  30. // Get image handle
  31. //
  32. var smallImage = document.getElementById('smallImage');
  33.  
  34. // Unhide image elements
  35. //
  36. smallImage.style.display = 'block';
  37.  
  38. // Show the captured photo
  39. // The inline CSS rules are used to resize the image
  40. //
  41. smallImage.src = "data:image/jpeg;base64," + imageData;
  42.  
  43. $.ajax({
  44. type: "POST",
  45. url: "http://seite.de/base64/index.php",
  46. data: "image_base64=" + imageData,
  47. success: function(msg){
  48. alert( "Data Saved: " + msg );
  49. }
  50. });
  51.  
  52. }
  53.  
  54. // Called when a photo is successfully retrieved
  55. //
  56. function onPhotoURISuccess(imageURI) {
  57. // Uncomment to view the image file URI
  58. // console.log(imageURI);
  59.  
  60. // Get image handle
  61. //
  62. var largeImage = document.getElementById('largeImage');
  63.  
  64. // Unhide image elements
  65. //
  66. largeImage.style.display = 'block';
  67.  
  68. // Show the captured photo
  69. // The inline CSS rules are used to resize the image
  70. //
  71. largeImage.src = imageURI;
  72. }
  73.  
  74. // A button will call this function
  75. //
  76. function capturePhoto() {
  77. // Take picture using device camera and retrieve image as base64-encoded string
  78. navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
  79. }
  80.  
  81. // A button will call this function
  82. //
  83. function capturePhotoEdit() {
  84. // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
  85. navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true });
  86. }
  87.  
  88. // A button will call this function
  89. //
  90. function getPhoto(source) {
  91. // Retrieve image file location from specified source
  92. navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
  93. destinationType: destinationType.FILE_URI,
  94. sourceType: source });
  95. }
  96.  
  97. // Called if something bad happens.
  98. //
  99. function onFail(message) {
  100. alert('Failed because: ' + message);
  101. }
  102.  
  103. </script>
  104. </head>
  105. <body>
  106. <button onclick="capturePhoto();">Capture Photo</button> <br>
  107. <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
  108. <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
  109. <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
  110. <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
  111. <img style="display:none;" id="largeImage" src="" />
  112. </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement