jocontacter / asceticcropper

ascetic cropper repo
MIT License
9 stars 2 forks source link

How to assign ImageSource to PhotoSource of ImageCropperView? #4

Open abraham891 opened 3 years ago

abraham891 commented 3 years ago

I want to assign an image source to cropper.PhotoSource.

public Crop(ImageSource img) { InitializeComponent(); cropper.PhotoSource = img; BindingContext = new MainViewModel(this); }

But this throw the error : "Property or Indexer 'ImageCropperView.PhotoSource' cannot be assigned to -- it is read only".

How we can do it?

jocontacter commented 3 years ago

Yes, it is bug. Try like this as workaround: cropper.SetValue(ImageCropperView.PhotoSourceProperty, img);

abraham891 commented 3 years ago

This is producing a System.NullReferenceException error.

jocontacter commented 3 years ago

This is producing a System.NullReferenceException error.

Nope. I tried it. What is in your ImageSource? Can you make repro?

abraham891 commented 3 years ago

I just rearranged the code. Now instead of passing ImageSource in cunstructor, i've added an "Pick Image" Button and using Xamarin.Essentials.MediaPicker to fetch file from gallery and pass it as PhotoSource of ImageCropperView.

This still producing a System.NullReferenceException error.

Attached a ZIP file below.

CropImage.zip

jocontacter commented 3 years ago

Thanks! I'll fix it on the weekend

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at FFImageLoading.Extensions.PImageExtensions.AsJpegStream (UIKit.UIImage image, System.Int32 quality) [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Extensions\PImageExtensions.cs:92 
  at FFImageLoading.TaskParameterPlatformExtensions.AsJPGStreamAsync (FFImageLoading.Work.TaskParameter parameters, System.Int32 quality) [0x0006d] in C:\projects\ffimageloading\source\FFImageLoading.Touch\Extensions\TaskParameterPlatformExtensions.cs:37 
  at Sample.ImageCrop.Crop () [0x00031] in /Users/jocontacter/Projects/AsceticCropper/Example/ImageCrop.xaml.cs:42 
  at Sample.MainViewModel+<>c__DisplayClass14_0.<.ctor>b__0 () [0x00030] in /Users/jocontacter/Projects/AsceticCropper/Example/ImageCrop.xaml.cs:77 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178 
jocontacter commented 3 years ago

By the way, I'm inclined to conclude that the Essentials plugin is to blame. Try with Media plugin. Also, try without cropper - will it work with direct picture?(edit: yes, it work) In any case, there is such a bug, I will figure out whether he was involved in this

brunonocetti commented 2 years ago

@jocontacter did you get a chance to look into this?