【问题标题】:Com.Theartofdev.Edmodo.Cropper library result code cancelledCom.Theartofdev.Edmodo.Cropper 库结果代码已取消
【发布时间】:2021-05-22 15:58:24
【问题描述】:

我无法使用 Com.Theartofdev.Edmodo.Cropper 库获得结果代码“OK”OnActivityResult。即使我实际上是从中按下裁剪,它也会被取消,因为库会自动显示裁剪工具。使用此代码。它会让你从你的设备中选择图像,当我按下裁剪时没有任何反应,发现结果代码被取消了。

CropImage.Builder()
                  .SetGuidelines(CropImageView.Guidelines.On).SetCropShape(CropImageView.CropShape.Oval).SetFixAspectRatio(true)
                  .Start(this);

(图片不是我的,来自这里“https://bintray.com/arthurhub/maven/Android-Image-Cropper#”)

我的目标是从 OnActivityResult 中获取 uri 并将其显示在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();
                }


            }
        }

它说在文档上只使用 OnActivityResult 从工具中获取裁剪的图像,但我无法将结果代码设为“Ok”。我真的猜我做错了,或者我遗漏了很多部分。

【问题讨论】:

    标签: c# xamarin xamarin.android


    【解决方案1】:

    我能够通过将 OnActivityResult 从旧的重写为这个来实现目标,

        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);
        }
    

    也可以通过从 OnCreate 中删除此行,

             StartActivityForResult(Intent, 200);
    

    我只是使用了一个简单的 imageview 而不是cropviewimage。

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      相关资源
      最近更新 更多