diff --git a/ImageCropper.Forms.sln b/ImageCropper.Forms.sln index 48bdf3a6..de50aa62 100644 --- a/ImageCropper.Forms.sln +++ b/ImageCropper.Forms.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2024 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Android", "Test\Test.Android\Test.Android.csproj", "{21888A92-3966-474B-BFD8-04E6DC7A260F}" EndProject @@ -67,6 +67,7 @@ Global {21888A92-3966-474B-BFD8-04E6DC7A260F}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU {21888A92-3966-474B-BFD8-04E6DC7A260F}.AppStore|iPhoneSimulator.Deploy.0 = Release|Any CPU {21888A92-3966-474B-BFD8-04E6DC7A260F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21888A92-3966-474B-BFD8-04E6DC7A260F}.Debug|Any CPU.Build.0 = Debug|Any CPU {21888A92-3966-474B-BFD8-04E6DC7A260F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {21888A92-3966-474B-BFD8-04E6DC7A260F}.Debug|iPhone.ActiveCfg = Debug|Any CPU {21888A92-3966-474B-BFD8-04E6DC7A260F}.Debug|iPhone.Build.0 = Debug|Any CPU @@ -94,6 +95,7 @@ Global {5AE225C1-20C1-444A-ABD7-547965282F49}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator {5AE225C1-20C1-444A-ABD7-547965282F49}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator {5AE225C1-20C1-444A-ABD7-547965282F49}.Debug|Any CPU.ActiveCfg = Debug|iPhone + {5AE225C1-20C1-444A-ABD7-547965282F49}.Debug|Any CPU.Build.0 = Debug|iPhone {5AE225C1-20C1-444A-ABD7-547965282F49}.Debug|iPhone.ActiveCfg = Debug|iPhone {5AE225C1-20C1-444A-ABD7-547965282F49}.Debug|iPhone.Build.0 = Debug|iPhone {5AE225C1-20C1-444A-ABD7-547965282F49}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator @@ -116,6 +118,7 @@ Global {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.Debug|iPhone.ActiveCfg = Debug|Any CPU {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.Debug|iPhone.Build.0 = Debug|Any CPU {7B7692F4-D2C1-4FE8-B4EB-33C2E25E7C44}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU diff --git a/ImageCropper.nuspec b/ImageCropper.nuspec index c824ea62..f0cd6cf3 100644 --- a/ImageCropper.nuspec +++ b/ImageCropper.nuspec @@ -1,37 +1,40 @@ - ImageCropper.Forms.Fix.v2 - 1.0.5 + ImageCropper.Forms.Fix.MultiPicker + 1.0.7 Marko Rothstein Marko Rothstein https://github.com/INHack20/ImageCropper.Forms - https://github.com/INHack20/ImageCropper.Forms/blob/master/LICENSE.md + https://github.com/INHack20/ImageCropper.Forms/blob/master/LICENSE.md false Xamarin.Forms plugin to crop and rotate photos. - Xamarin.Forms plugin to crop and rotate photos. Supports Android and iOS. + Xamarin.Forms plugin to crop and rotate photos taken by the Camera or Picked multiple images from Gallery. Supports Android and iOS. First release. © StormLion 2018 - xamarin forms crop rotate photo image + xamarin forms crop rotate photo image multipicker + + + - + - + diff --git a/ImageCropper/ImageCropper.Android/ImageCropper.Android.csproj b/ImageCropper/ImageCropper.Android/ImageCropper.Android.csproj index f9427b3a..9660a1ca 100644 --- a/ImageCropper/ImageCropper.Android/ImageCropper.Android.csproj +++ b/ImageCropper/ImageCropper.Android/ImageCropper.Android.csproj @@ -1,4 +1,4 @@ - + Debug @@ -62,6 +62,9 @@ + + 1.0.1 + 6.0.1 @@ -77,6 +80,7 @@ 4.5.0.725 - + + \ No newline at end of file diff --git a/ImageCropper/ImageCropper.Android/ImageCropperImplementation.cs b/ImageCropper/ImageCropper.Android/ImageCropperImplementation.cs index 2c039e7c..37c93d2b 100644 --- a/ImageCropper/ImageCropper.Android/ImageCropperImplementation.cs +++ b/ImageCropper/ImageCropper.Android/ImageCropperImplementation.cs @@ -1,51 +1,54 @@ using Com.Theartofdev.Edmodo.Cropper; -using Stormlion.ImageCropper.Droid; using System.Diagnostics; -using Xamarin.Forms; using System; -using Xamarin.Essentials; +using System.Collections.Generic; namespace Stormlion.ImageCropper.Droid { public class ImageCropperImplementation : IImageCropperWrapper { - public void ShowFromFile(ImageCropper imageCropper, string imageFile) + public void ShowFromFile(ImageCropper imageCropper, List imagesCroppingList) { try { - CropImage.ActivityBuilder activityBuilder = CropImage.Activity(Android.Net.Uri.FromFile(new Java.IO.File(imageFile))); + CropImage.ActivityBuilder activityBuilder; - if(imageCropper.CropShape == ImageCropper.CropShapeType.Oval) + foreach (var imageFile in imagesCroppingList) { - activityBuilder.SetCropShape(CropImageView.CropShape.Oval); - } - else - { - activityBuilder.SetCropShape(CropImageView.CropShape.Rectangle); - } + activityBuilder = CropImage.Activity(Android.Net.Uri.FromFile(new Java.IO.File(imageFile.ImagePath))); - if(imageCropper.AspectRatioX > 0 && imageCropper.AspectRatioY > 0) - { - activityBuilder.SetFixAspectRatio(true); - activityBuilder.SetAspectRatio(imageCropper.AspectRatioX, imageCropper.AspectRatioY); - } - else - { - activityBuilder.SetFixAspectRatio(false); - } + if (imageCropper.CropShape == ImageCropper.CropShapeType.Oval) + { + activityBuilder.SetCropShape(CropImageView.CropShape.Oval); + } + else + { + activityBuilder.SetCropShape(CropImageView.CropShape.Rectangle); + } - if(!string.IsNullOrWhiteSpace(imageCropper.PageTitle)) - { - activityBuilder.SetActivityTitle(imageCropper.PageTitle); - } + if (imageCropper.AspectRatioX > 0 && imageCropper.AspectRatioY > 0) + { + activityBuilder.SetFixAspectRatio(true); + activityBuilder.SetAspectRatio(imageCropper.AspectRatioX, imageCropper.AspectRatioY); + } + else + { + activityBuilder.SetFixAspectRatio(false); + } - activityBuilder.Start(Xamarin.Essentials.Platform.CurrentActivity); + if (!string.IsNullOrWhiteSpace(imageCropper.PageTitle)) + { + activityBuilder.SetActivityTitle(imageCropper.PageTitle); + } + + activityBuilder.Start(Xamarin.Essentials.Platform.CurrentActivity); + } } - catch(Exception ex) + catch (Exception ex) { Debug.WriteLine(ex.ToString()); } - + } } } \ No newline at end of file diff --git a/ImageCropper/ImageCropper.Android/Platform.cs b/ImageCropper/ImageCropper.Android/Platform.cs index ea8d0a34..bf8f86df 100644 --- a/ImageCropper/ImageCropper.Android/Platform.cs +++ b/ImageCropper/ImageCropper.Android/Platform.cs @@ -15,19 +15,54 @@ public static void Init() public static async void OnActivityResult(int requestCode, Result resultCode, Intent data) { - if (requestCode == CropImage.CropImageActivityRequestCode) + if (data == null) { - CropImage.ActivityResult result = CropImage.GetActivityResult(data); + ImageCropper.Current.indexCounter++; + return; + } - // small delay - await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(100)); - if (resultCode == Result.Ok) - { - ImageCropper.Current.Success?.Invoke(result.Uri.Path); - } - else if ((int)resultCode == (int)(CropImage.CropImageActivityResultErrorCode)) + else + { + if (requestCode == CropImage.CropImageActivityRequestCode) { - ImageCropper.Current.Faiure?.Invoke(); + string originalFileCreationDate = string.Empty; + + originalFileCreationDate = ImageCropper.Current. + BeforeCroppingList[ImageCropper.Current. + indexCounter].OriginalPictureDate; + + CropImage.ActivityResult result = CropImage.GetActivityResult(data); + + if (result != null) + { + ImageCropper.Current.CroppingResultList.Add(new ImageProperties() + { + ImagePath = result.Uri.Path, + OriginalPictureDate = originalFileCreationDate + }); + + ImageCropper.Current.indexCounter++; + + // small delay + await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(100)); + + if (resultCode == Result.Ok) + { + if (ImageCropper.Current.indexCounter == ImageCropper.Current.BeforeCroppingList.Count) + { + ImageCropper.Current.Success?.Invoke(ImageCropper.Current.CroppingResultList); + } + } + else if ((int)resultCode == (int)(CropImage.CropImageActivityResultErrorCode)) + { + ImageCropper.Current.Faiure?.Invoke(); + } + } + else + { + ImageCropper.Current.Faiure?.Invoke(); + return; + } } } } diff --git a/ImageCropper/ImageCropper.iOS/ImageCropper.iOS.csproj b/ImageCropper/ImageCropper.iOS/ImageCropper.iOS.csproj index ff7382a0..27669e4c 100644 --- a/ImageCropper/ImageCropper.iOS/ImageCropper.iOS.csproj +++ b/ImageCropper/ImageCropper.iOS/ImageCropper.iOS.csproj @@ -39,9 +39,6 @@ - - - @@ -57,14 +54,6 @@ ImageCropper - - - false - - - false - - 6.0.1 @@ -77,4 +66,4 @@ - \ No newline at end of file + diff --git a/ImageCropper/ImageCropper.iOS/ImageCropperImplementation.cs b/ImageCropper/ImageCropper.iOS/ImageCropperImplementation.cs index ee58e0ad..2b932425 100644 --- a/ImageCropper/ImageCropper.iOS/ImageCropperImplementation.cs +++ b/ImageCropper/ImageCropper.iOS/ImageCropperImplementation.cs @@ -1,84 +1,119 @@ using Bind_TOCropViewController; using CoreGraphics; using Foundation; -using Plugin.Media.Abstractions; -using Stormlion.ImageCropper.iOS; using System; +using System.Collections.Generic; using System.Diagnostics; using UIKit; -using Xamarin.Forms; namespace Stormlion.ImageCropper.iOS { - public class ImageCropperImplementation : IImageCropperWrapper + public class ImageCropperImplementation : IImageCropperWrapper { - public void ShowFromFile(ImageCropper imageCropper, string imageFile) + public void ShowFromFile(ImageCropper imageCropper, List imagesCroppingList) { - UIImage image = UIImage.FromFile(imageFile); + try + { + TOCropViewController cropViewController; - TOCropViewController cropViewController; + var temporalList = imagesCroppingList; - if(imageCropper.CropShape == ImageCropper.CropShapeType.Oval) - { - cropViewController = new TOCropViewController(TOCropViewCroppingStyle.Circular, image); - } - else - { - cropViewController = new TOCropViewController(image); - } + foreach (var imageFile in temporalList) + { + UIImage image = UIImage.FromFile(imageFile.ImagePath); - if(imageCropper.AspectRatioX > 0 && imageCropper.AspectRatioY > 0) - { - cropViewController.AspectRatioPreset = TOCropViewControllerAspectRatioPreset.Custom; - cropViewController.ResetAspectRatioEnabled = false; - cropViewController.AspectRatioLockEnabled = true; - cropViewController.CustomAspectRatio = new CGSize(imageCropper.AspectRatioX, imageCropper.AspectRatioY); - } + cropViewController = imageCropper.CropShape == ImageCropper.CropShapeType.Oval ? new TOCropViewController(TOCropViewCroppingStyle.Circular, image) : new TOCropViewController(image); - cropViewController.OnDidCropToRect = (outImage, cropRect, angle) => - { - Finalize(imageCropper, outImage); - }; + if (imageCropper.AspectRatioX > 0 && imageCropper.AspectRatioY > 0) + { + cropViewController.AspectRatioPreset = TOCropViewControllerAspectRatioPreset.Custom; + cropViewController.ResetAspectRatioEnabled = false; + cropViewController.AspectRatioLockEnabled = true; + cropViewController.CustomAspectRatio = new CGSize(imageCropper.AspectRatioX, imageCropper.AspectRatioY); + } - cropViewController.OnDidCropToCircleImage = (outImage, cropRect, angle) => - { - Finalize(imageCropper, outImage); - }; + cropViewController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; - cropViewController.OnDidFinishCancelled = (cancelled) => - { - imageCropper.Faiure?.Invoke(); - UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); - }; + cropViewController.OnDidCropToRect = (outImage, cropRect, angle) => + { + int tempIndex = temporalList.FindIndex(x => x.ImagePath.Equals(imageFile.ImagePath) && x.OriginalPictureDate.Equals(imageFile.OriginalPictureDate)); + + temporalList.RemoveAt(tempIndex); + + Finalize(imageCropper, outImage, imageFile.OriginalPictureDate, temporalList); + UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); + + if (temporalList.Count > 0) + ShowFromFile(imageCropper, temporalList); + + if (temporalList.Count == 0 && imageCropper.CroppingResultList.Count > 0) + FinishCroppingTask(imageCropper); + }; + + cropViewController.OnDidCropToCircleImage = (outImage, cropRect, angle) => + { + Finalize(imageCropper, outImage, imageFile.OriginalPictureDate, temporalList); + }; - UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(cropViewController, true, null); + cropViewController.OnDidFinishCancelled = (cancelled) => + { + int tempIndex = temporalList.FindIndex(x => x.ImagePath.Equals(imageFile.ImagePath) && x.OriginalPictureDate.Equals(imageFile.OriginalPictureDate)); - if (!string.IsNullOrWhiteSpace(imageCropper.PageTitle) && cropViewController.TitleLabel != null) + temporalList.RemoveAt(tempIndex); + + UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); + + if (temporalList.Count > 0) + ShowFromFile(imageCropper, temporalList); + + if (temporalList.Count == 0 && imageCropper.CroppingResultList.Count > 0) + FinishCroppingTask(imageCropper); + }; + UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(cropViewController, true, null); + + if (!string.IsNullOrWhiteSpace(imageCropper.PageTitle) && cropViewController.TitleLabel != null) + { + UILabel titleLabel = cropViewController.TitleLabel; + titleLabel.Text = imageCropper.PageTitle; + } + } + } + catch (Exception ex) { - UILabel titleLabel = cropViewController.TitleLabel; - titleLabel.Text = imageCropper.PageTitle; + Console.WriteLine(ex); } } - private static async void Finalize(ImageCropper imageCropper, UIImage image) + private static async void Finalize(ImageCropper imageCropper, UIImage image, string imageCreationDate, List imagePropertiesList) { string documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string jpgFilename = System.IO.Path.Combine(documentsDirectory, Guid.NewGuid().ToString() + ".jpg"); NSData imgData = image.AsJPEG(); NSError err; + imageCropper.CroppingResultList.Add(new ImageProperties() + { + ImagePath = jpgFilename, + OriginalPictureDate = imageCreationDate + }); + // small delay await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(100)); - if (imgData.Save(jpgFilename, false, out err)) - { - imageCropper.Success?.Invoke(jpgFilename); - } - else + + if (!imgData.Save(jpgFilename, false, out err)) { Debug.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription); imageCropper.Faiure?.Invoke(); } UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); } + + private static async void FinishCroppingTask(ImageCropper imageCropper) + { + // small delay + await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(100)); + + imageCropper.Success?.Invoke(imageCropper.CroppingResultList); + } } } \ No newline at end of file diff --git a/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Contents.json b/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Contents.json index afae4480..e69de29b 100644 --- a/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Contents.json +++ b/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Contents.json @@ -1,27 +0,0 @@ -{ - "images": [ - { - "scale": "1x", - "idiom": "universal" - }, - { - "scale": "2x", - "idiom": "universal", - "filename": "Photo.png" - }, - { - "scale": "3x", - "idiom": "universal" - }, - { - "idiom": "universal" - } - ], - "properties": { - "template-rendering-intent": "" - }, - "info": { - "version": 1, - "author": "" - } -} \ No newline at end of file diff --git a/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Photo.png b/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Photo.png deleted file mode 100644 index 51275da1..00000000 Binary files a/ImageCropper/ImageCropper.iOS/Resources/Media.xcassets/sample1.imageset/Photo.png and /dev/null differ diff --git a/ImageCropper/ImageCropper/IImageCropperWrapper.cs b/ImageCropper/ImageCropper/IImageCropperWrapper.cs index d48af3e0..27c9d9c4 100644 --- a/ImageCropper/ImageCropper/IImageCropperWrapper.cs +++ b/ImageCropper/ImageCropper/IImageCropperWrapper.cs @@ -1,9 +1,9 @@ -using Plugin.Media.Abstractions; +using System.Collections.Generic; namespace Stormlion.ImageCropper { public interface IImageCropperWrapper { - void ShowFromFile(ImageCropper imageCropper, string imageFile); + void ShowFromFile(ImageCropper imageCropper, List imagesCroppingList); } -} +} \ No newline at end of file diff --git a/ImageCropper/ImageCropper/ImageCropper.cs b/ImageCropper/ImageCropper/ImageCropper.cs index 29220698..cfde4b62 100644 --- a/ImageCropper/ImageCropper/ImageCropper.cs +++ b/ImageCropper/ImageCropper/ImageCropper.cs @@ -1,6 +1,8 @@ using Plugin.Media; using Plugin.Media.Abstractions; using System; +using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using Xamarin.Forms; @@ -31,13 +33,24 @@ public enum CropShapeType public string SelectSourceTitle { get; set; } = "Select source"; - public string TakePhotoTitle { get; set; } = "Take Photo"; + public string TakePhotoTitle { get; set; } = "Camera"; - public string PhotoLibraryTitle { get; set; } = "Photo Library"; + public string PhotoLibraryTitle { get; set; } = "Gallery"; public string CancelButtonTitle { get; set; } = "Cancel"; - public Action Success { get; set; } + public string originalPicDate { get; set; } + + public int indexCounter { get; set; } = 0; + + public List BeforeCroppingList; + + public List CroppingResultList { get; set; } = new List(); + + /// + /// T1: List of Image cropped paths and Original Image Source Date of Creation. + /// + public Action> Success { get; set; } public Action Faiure { get; set; } @@ -48,54 +61,136 @@ public enum CropShapeType public StoreCameraMediaOptions StoreCameraMediaOptions { get; set; } = new StoreCameraMediaOptions(); - public async void Show(Page page, string imageFile = null) + public async void Show(Page page, List imageFiles = null) { - if(imageFile == null) + try { - await CrossMedia.Current.Initialize(); + if (imageFiles == null) + { + await CrossMedia.Current.Initialize(); - MediaFile file; + MediaFile file; + List files = null; - string action = await page.DisplayActionSheet(SelectSourceTitle, CancelButtonTitle, null, TakePhotoTitle, PhotoLibraryTitle); - if (action == TakePhotoTitle) - { - if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) + CroppingResultList.Clear(); + + string action = await page.DisplayActionSheet(SelectSourceTitle, CancelButtonTitle, null, TakePhotoTitle, PhotoLibraryTitle); + if (action == TakePhotoTitle) + { + if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) + { + await page.DisplayAlert("Error", "This device does not have camera available.", "OK"); + Faiure?.Invoke(); + return; + } + + file = await CrossMedia.Current.TakePhotoAsync(StoreCameraMediaOptions); + + if (file != null) + { + files = new List(); + + files.Add(file); + + BeforeCroppingList = new List(); + + BeforeCroppingList.Add(new ImageProperties() + { + ImagePath = file.Path, + OriginalPictureDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + }); + } + else + { + Faiure?.Invoke(); + return; + } + } + else if (action == PhotoLibraryTitle) + { + try + { + if (!CrossMedia.Current.IsPickPhotoSupported) + { + await page.DisplayAlert("Error", "This device is not supported to pick photo.", "OK"); + Faiure?.Invoke(); + return; + } + + PickMediaOptions.SaveMetaData = true; + + files = await CrossMedia.Current.PickPhotosAsync(PickMediaOptions); + + if (files.Count > 0) + { + BeforeCroppingList = new List(); + + foreach (var item in files) + { + Stream currentStream = item.GetStream(); + var currentPictureData = ExifLib.ExifReader.ReadJpeg(currentStream); + string CurrentPictureDate = currentPictureData.DateTimeOriginal; + originalPicDate = String.Empty; + + if (CurrentPictureDate != null) + { + string pictureDate = CurrentPictureDate. + Substring(startIndex: 0, 10).Replace(":", "/"); + string pictureTime = CurrentPictureDate.Substring(startIndex: 11); + originalPicDate = $"{pictureDate} {pictureTime}"; + } + else + { + originalPicDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + } + + BeforeCroppingList.Add(new ImageProperties() + { + ImagePath = item.Path, + OriginalPictureDate = originalPicDate + }); + } + } + else + { + Faiure?.Invoke(); + return; + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + files = null; + } + } + else { - await page.DisplayAlert("No Camera", ":( No camera available.", "OK"); Faiure?.Invoke(); return; } - file = await CrossMedia.Current.TakePhotoAsync(StoreCameraMediaOptions); - } - else if(action == PhotoLibraryTitle) - { - if(!CrossMedia.Current.IsPickPhotoSupported) + if (files == null) { - await page.DisplayAlert("Error", "This device is not supported to pick photo.", "OK"); Faiure?.Invoke(); return; } - file = await CrossMedia.Current.PickPhotoAsync(PickMediaOptions); } - else - { - Faiure?.Invoke(); - return; - } - - if (file == null) - { - Faiure?.Invoke(); - return; - } - - imageFile = file.Path; + } + catch (Exception ex) + { + Console.WriteLine(ex); } // small delay await Task.Delay(TimeSpan.FromMilliseconds(100)); - DependencyService.Get().ShowFromFile(this, imageFile); + DependencyService.Get().ShowFromFile(this, BeforeCroppingList); } } -} + + public class ImageProperties + { + public string ImagePath { get; set; } + public string OriginalPictureDate { get; set; } + } + +} \ No newline at end of file diff --git a/ImageCropper/ImageCropper/ImageCropper.csproj b/ImageCropper/ImageCropper/ImageCropper.csproj index 1d20b06c..fd8c6bec 100644 --- a/ImageCropper/ImageCropper/ImageCropper.csproj +++ b/ImageCropper/ImageCropper/ImageCropper.csproj @@ -7,6 +7,7 @@ + diff --git a/Test/Test/MainPage.xaml.cs b/Test/Test/MainPage.xaml.cs index c60bc4eb..129f62cd 100644 --- a/Test/Test/MainPage.xaml.cs +++ b/Test/Test/MainPage.xaml.cs @@ -1,22 +1,15 @@ using Plugin.Media; -using Plugin.Media.Abstractions; using Stormlion.ImageCropper; using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xamarin.Forms; namespace Test { - public partial class MainPage : ContentPage - { - public MainPage() - { - InitializeComponent(); + public partial class MainPage : ContentPage + { + public MainPage() + { + InitializeComponent(); CrossMedia.Current.Initialize(); } @@ -25,14 +18,16 @@ protected async void OnClickedRectangle(object sender, EventArgs e) { new ImageCropper() { -// PageTitle = "Test Title", -// AspectRatioX = 1, -// AspectRatioY = 1, - Success = (imageFile) => + // PageTitle = "Test Title", + // AspectRatioX = 1, + // AspectRatioY = 1, + Success = (croppingResultList) => { Device.BeginInvokeOnMainThread(() => { - imageView.Source = ImageSource.FromFile(imageFile); + imageView.Source = ImageSource.FromFile(croppingResultList[0].ImagePath); + string imagePath = croppingResultList[0].ImagePath; + string imageDate = croppingResultList[0].OriginalPictureDate; }); } }.Show(this); @@ -43,11 +38,11 @@ private void OnClickedCircle(object sender, EventArgs e) new ImageCropper() { CropShape = ImageCropper.CropShapeType.Oval, - Success = (imageFile) => + Success = (croppingResultList) => { Device.BeginInvokeOnMainThread(() => { - imageView.Source = ImageSource.FromFile(imageFile); + imageView.Source = ImageSource.FromFile(croppingResultList[0].ImagePath); }); } }.Show(this);