Issue
I could not get the result code "OK" OnActivityResult using Com.Theartofdev.Edmodo.Cropper library. It was resulting cancelled even though I am actually pressing the crop from it, Since the library will automatically display the tool for cropping. using this code. It will let you pick image from your device and when I am pressing the crop nothing happens and found out the resultcode is cancelled.
CropImage.Builder()
.SetGuidelines(CropImageView.Guidelines.On).SetCropShape(CropImageView.CropShape.Oval).SetFixAspectRatio(true)
.Start(this);
(Image not mine, came from here "https://bintray.com/arthurhub/maven/Android-Image-Cropper#")
My goal is to get the uri from the OnActivityResult and display it on a cropimageview.
CropImageView cropImageView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.cropView);
cropImageView = (CropImageView)FindViewById(Resource.Id.cropImageView);
CropImage.Builder()
.SetGuidelines(CropImageView.Guidelines.On).SetCropShape(CropImageView.CropShape.Oval).SetFixAspectRatio(true)
.Start(this);
StartActivityForResult(Intent, 200);
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
if (requestCode == CropImage.PickImageChooserRequestCode)
{
try
{
CropImage.ActivityResult result = CropImage.GetActivityResult(data);
if (resultCode == Result.Ok)
{
Android.Net.Uri resultUri = result.Uri;
cropImageView.SetImageUriAsync(resultUri);
}
}
catch
{
Toast.MakeText(Application.Context, "Error", ToastLength.Long).Show();
}
}
}
It says that on the documentation just use the OnActivityResult to get the cropped image from the tool but I could not make the result code to be "Ok". I really guess I'm doing it wrong or I am missing lots of parts of it.
Solution
I was able to get the objective by rewriting the OnActivityResult from the old one to this,
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (requestCode == CropImage.CropImageActivityRequestCode)
{
CropImage.ActivityResult result = CropImage.GetActivityResult(data);
if (resultCode == Result.Ok)
{
Android.Net.Uri resultUri = result.Uri;
profilepiC.SetImageURI(resultUri);
}
else if (resultCode == (Result)CropImage.CropImageActivityResultErrorCode)
{
System.Exception error = result.Error;
Toast.MakeText(this, error.Message, ToastLength.Long).Show();
}
}
base.OnActivityResult(requestCode, resultCode, data);
}
also by removing this line from OnCreate,
StartActivityForResult(Intent, 200);
And i did just use a simple imageview rather than a cropviewimage.
Answered By - psy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.