Xamarin.Forms Capture and Crop an Image for Android platform

How can we achieve below functionality in Xamarin.Forms for Android platform?

  1. Capture Image from Camera
  2. Load Image from gallery
  3. Crop Image either from Camera image/Gallery Image
  4. Load/Select Image in Image Tag

Please provide code as I am new in xamarin world.

Posts

  • Hello Xamarin,

    Can you please respond on this thread as I am struggling from couple of days?

  • MehdyMehdy USMember

    start with installing xam.plugin.media nuget package and read docs here:
    https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Media

  • waqasashiqwaqasashiq PKMember

    I have used the media plugin for cross platform, but image cropping is not working on android platform.
    Can you please help me?

  • RenjithPRenjithP USMember

    @JamesMontemagno Image cropping in not working for android. i have set the AllowCropping=true when taking photos
    TakePhotoAsync

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    @RenjithP if you read the Readme you will see cropping is only supported on iOS and UWP: https://github.com/jamesmontemagno/mediaplugin#allow-cropping

  • Vaka.GopiNadhReddyVaka.GopiNadhReddy USMember ✭✭✭

    Hi, I done this in Xamarin.Forms, here is the sample.......

  • SreeeeSreeee INMember ✭✭✭✭✭

    @DineshPatankar said:
    How can we achieve below functionality in Xamarin.Forms for Android platform?

    1. Capture Image from Camera
    2. Load Image from gallery
    3. Crop Image either from Camera image/Gallery Image
    4. Load/Select Image in Image Tag

    Please provide code as I am new in xamarin world.

    Did you solve this issue?

  • SreeeeSreeee INMember ✭✭✭✭✭

    @JamesMontemagno said:
    @RenjithP if you read the Readme you will see cropping is only supported on iOS and UWP: https://github.com/jamesmontemagno/mediaplugin#allow-cropping

    Is it possible to crop UWP gallery pictures?

  • SreeeeSreeee INMember ✭✭✭✭✭

    @Vaka.GopiNadhReddy said:
    Hi, I done this in Xamarin.Forms, here is the sample.......

    I download your zip, but it is not running in my VS. Showing Project not selected to build for this solution configuration in output window.

  • Vaka.GopiNadhReddyVaka.GopiNadhReddy USMember ✭✭✭

    @Sreeee please check once again, because it's working in my case.

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @Sreeee said:

    @Vaka.GopiNadhReddy said:
    Hi, I done this in Xamarin.Forms, here is the sample.......

    I download your zip, but it is not running in my VS. Showing Project not selected to build for this solution configuration in output window.

    **Right Click solution>properties>configuration properties> make sure both build and deploy checked **

  • SreeeeSreeee INMember ✭✭✭✭✭

    @Charwaka said:

    @Sreeee said:

    @Vaka.GopiNadhReddy said:
    Hi, I done this in Xamarin.Forms, here is the sample.......

    I download your zip, but it is not running in my VS. Showing Project not selected to build for this solution configuration in output window.

    **Right Click solution>properties>configuration properties> make sure both build and deploy checked **

    Deploy is unchecked for mine. Checked it and it started working on my vs. Thank you :)

  • SreeeeSreeee INMember ✭✭✭✭✭

    @Vaka.GopiNadhReddy said:
    @Sreeee please check once again, because it's working in my case.

    I integrate your code into my project. Getting an exception :

    Exception:>System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
    at SmartWCM.CrossXMethod.get_Current () [0x00015] in F:\Back_Up_Copy\SmartWCM\SmartWCM\IXCrossCropImage.cs:23
    at SmartWCM.NewTweetPage+d__8.MoveNext () [0x00206] in F:\Back_Up_Copy\SmartWCM\SmartWCM\NewTweetPage.xaml.cs:174

    Are you using any new nuget packages? What is the use of XViewEventArgs class? I didn't add that to my project.

  • SreeeeSreeee INMember ✭✭✭✭✭

    Hi, @Charwaka Did you try this?

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @Sreeee said:
    Hi, @Charwaka Did you try this?

    Install same nuget packges in all projects PCL,android,ios,UWP

  • m_rashid_sm_rashid_s Member ✭✭

    @Vaka.GopiNadhReddy
    I downloaded crosssample.zip and it is working well in android. Now I am trying to integrate this functionality into my project and I copied all the files to my project. Here I am getting error (red line) in cropimage.cs
    SetContentView(Resource.Layout.cropimage); // red line in .cropimage
    FindViewById(Resource.Id.discard).Click += (sender, e) => { OnDisCardClick(); }; // red line in Resource.Id.discard
    FindViewById(Resource.Id.save).Click += (sender, e) => { OnSaveClicked(); }; // red line in Resource.Id.save

            FindViewById<Button>(Resource.Id.rotateLeft).Click += (o, e) => // red line in rotateLeft
            {
                _bitmap = Util.RotateImage(_bitmap, -90);
                var rotateBitmap = new RotateBitmap(_bitmap);
                _imageView.SetImageRotateBitmapResetBase(rotateBitmap, true);
                AddHighlightView();
            };
    
            FindViewById<Button>(Resource.Id.rotateRight).Click += (o, e) =>    // red line in rotateRight
            {
                _bitmap = Util.RotateImage(_bitmap, 90);
                var rotateBitmap = new RotateBitmap(_bitmap);
                _imageView.SetImageRotateBitmapResetBase(rotateBitmap, true);
                AddHighlightView();
            };
    

    Please can you help me here.

    Regards,

    Rashid

  • m_rashid_sm_rashid_s Member ✭✭

    @Vaka.GopiNadhReddy Yes I managed to do that. I missed the file in layout folder.
    I am able to integrate your sample to my android project successfully and now I am trying to do this is IOS project.

    Thanks once again.

    Regards

Sign In or Register to comment.