android - 如何使用 ImageCropper.Forms 拍照和裁剪? [英] android - How to take a photo and crop using ImageCropper.Forms?

查看:18
本文介绍了android - 如何使用 ImageCropper.Forms 拍照和裁剪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里不提供任何帮助..我正在使用 xamarin 并希望:

  1. 点击按钮
  2. 打开相机
  3. 拍照
  4. 裁剪照片
  5. 在图库中创建文件夹
  6. 将裁剪后的照片保存在图库的新文件夹中

我正在学习教程 - 参考:

或者您可以从设备中选择要裁剪的图像.

输出:

https://imgur.com/okWKHfk

ill take any help here.. I am using xamarin and would like to:

  1. Click on button
  2. Open Camera
  3. Take photo
  4. Crop Photo
  5. Create Folder in Gallery
  6. Save Cropped photo in new folder in Gallery

I am following tutorial - Ref: https://github.com/stormlion227/ImageCropper.Forms

Currently, When I tap on button, Camera opens up, but it doesnt crops or saves photo. Since Camera opens up, that means my set up and perrmission are correct.

Why this code isnt working from github and how can I crop photo? Please let me know what am I missing here.

after doing some debugging, following code is not getting runned. i this issue is with properties

 Device.BeginInvokeOnMainThread(() =>
                    {
                        ImageURL.Source = ImageSource.FromFile(imageFile);
                    });

view back-end

    public partial class AddCardPage : ContentPage
    {
        public AddCardPage()
        {
            InitializeComponent();
            CrossMedia.Current.Initialize();
        }

        protected async void TapGestureRecognizerCommand(object sender, EventArgs e)
        {
            try
            {
                await CrossMedia.Current.Initialize();


                await new ImageCropper()
                {
                    PageTitle = "Test Title",
                    AspectRatioX = 1,
                    AspectRatioY = 1,
                    CropShape = ImageCropper.CropShapeType.Rectangle, //Cropt shape
                    SelectSourceTitle = "Select source",
                    TakePhotoTitle = "Take Photo",
                    PhotoLibraryTitle = "Photo Library",
                    Success = (imageFile) =>
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            ImageURL.Source = ImageSource.FromFile(imageFile);
                        });
                    }
                }.Show(this);
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Debug.WriteLine("CameraException:>" + ex);
            }
        }//end of method

    }//end of class
}

Other Info: I downloaded 2 nugets: ImageCropper.Forms.Fix.v7 and Xam.Media.Plugin

解决方案

The plugin you used is too old. You could use ImageCropper.Forms.Fix.v2 instead.

Add the code below in your MainActivity:

   Stormlion.ImageCropper.Droid.Platform.Init();
   protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        Stormlion.ImageCropper.Droid.Platform.OnActivityResult(requestCode, resultCode, data);
    }

Add the code in tag of AndroidManifest.xaml:

<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" />

Code behind:

 new ImageCropper()
        {
            //                PageTitle = "Test Title",
            //                AspectRatioX = 1,
            //                AspectRatioY = 1,
            Success = (imageFile) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    image.Source = ImageSource.FromFile(imageFile);
                });
            }
        }.Show(this);

When you click the button, it would pop up a window. If you want to take photo, choose the Take Photo. Please note, you need to add the CAMERA permission.

<uses-permission android:name="android.permission.CAMERA" />

Or you could select the image from the device to crop.

OutPut:

https://imgur.com/okWKHfk

这篇关于android - 如何使用 ImageCropper.Forms 拍照和裁剪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆