[英]android - How to take a photo and crop using ImageCropper.Forms?
ill take any help here.. I am using xamarin and would like to:我会在这里寻求帮助。我正在使用 xamarin 并希望:
I am following tutorial - Ref: https://github.com/stormlion227/ImageCropper.Forms我正在关注教程 -参考: 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?为什么此代码不能从 github 工作,我该如何裁剪照片? 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其他信息:我下载了 2 个 nuget: ImageCropper.Forms.Fix.v7和Xam.Media.Plugin
The plugin you used is too old.您使用的插件太旧了。 You could use
ImageCropper.Forms.Fix.v2
instead.您可以改用
ImageCropper.Forms.Fix.v2
。
Add the code below in your MainActivity:在您的 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:在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.当你点击按钮时,它会弹出一个 window。 If you want to take photo, choose the
Take Photo
.如果要拍照,请选择
Take Photo
。 Please note, you need to add the CAMERA
permission.请注意,您需要添加
CAMERA
权限。
<uses-permission android:name="android.permission.CAMERA" />
Or you could select the image from the device to crop.或者您可以 select 从设备中裁剪图像。
OutPut: OutPut:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.