Guest User

Untitled

a guest
Oct 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. function getPhoto(src, target) {
  2. window.localStorage.removeItem('imageURI');
  3. var q = 30;
  4.  
  5. var imageOutput = target;
  6.  
  7. var opts = {
  8. destinationType: Camera.DestinationType.FILE_URI,
  9. quality: q
  10. }
  11.  
  12. switch(src) {
  13. case 'gallery':
  14. opts.sourceType = Camera.PictureSourceType.PHOTOLIBRARY;
  15. break;
  16.  
  17. default:
  18. opts.sourceType = Camera.PictureSourceType.CAMERA;
  19. break;
  20. }
  21.  
  22. function getPhotoFail(msg) { $(imageOutput).attr('src', ''); }
  23.  
  24. function getPhotoSuccess(imageURI) {
  25.  
  26. window.resolveLocalFileSystemURI(imageURI, resOnSuccess, resOnError);
  27.  
  28. function resOnSuccess(entry) {
  29. console.log('FILE NAME: ' + entry.name);
  30. entry.file(gotFile, noFile);
  31. }
  32.  
  33. function resOnError(err) {
  34. navigator.notification.alert('Unable to read file', null, 'FILE ERROR', 'OK');
  35. }
  36.  
  37. function gotFile(file) {
  38. var bytes = file.size;
  39. var kb = bytes / 1024;
  40.  
  41. console.log('BYTES: ' + bytes);
  42. console.log('KB: ' + kb);
  43.  
  44. window.localStorage.setItem('imageSize', kb);
  45.  
  46. // Store the image path for later use
  47. window.localStorage.setItem('imageURI', imageURI);
  48.  
  49. // Display image in <img> element
  50. $(imageOutput).attr('src', imageURI);
  51.  
  52. }
  53.  
  54. function noFile(err) {
  55.  
  56. }
  57. }
  58.  
  59. // GET PICTURE!
  60. navigator.camera.getPicture(getPhotoSuccess, getPhotoFail, opts);
  61. }
Add Comment
Please, Sign In to add comment