Guest User

Untitled

a guest
Nov 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. private void CaptureImageCommandHandler()
  2. {
  3. Device.BeginInvokeOnMainThread(async () =>
  4. {
  5. try
  6. {
  7. await CheckPermissionCamera();
  8.  
  9. if (Images == null)
  10. Images = new ObservableCollection<string>();
  11.  
  12. // Create a temp image. It'll be detelted after upload this temp image
  13. var path = await MediaManagement.TakePhoto();
  14. if (path == null)
  15. return;
  16.  
  17. // Add image
  18. AddImage(path, Localization.Resource.Photo);
  19. }
  20. catch (Exception ex)
  21. {
  22. Logger.Exception(ex);
  23. }
  24. });
  25. }
  26.  
  27. public async Task<string> TakePhoto(float? width = null, float? height = null)
  28. {
  29. try
  30. {
  31. await CrossMedia.Current.Initialize();
  32. var mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions());
  33. if (mediaFile?.Path == null)
  34. return null;
  35.  
  36. // This is: Taking a photo action
  37. var result = await ResizeImageFile(mediaFile.Path, width, height, true).ConfigureAwait(false);
  38. return result;
  39. }
  40. catch (Exception)
  41. {
  42. return null;
  43. }
  44. }
Add Comment
Please, Sign In to add comment