Issue
ill take any help here.. I am using xamarin and would like to:
- Click on button
- Open Camera
- Take photo
- Crop Photo
- Create Folder in Gallery
- 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
Solution
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:
Answered By - Wendy Zang - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.