how can I over lay a rectangle ontop of MediaPicker?

ikhlas ahmed 1 Reputation point
2021-05-11T19:05:13.897+00:00

I am using Xamarin Forms, how can I over lay a rectangle ontop of MediaPicker?

I know there are some some plugin out there like cross.media etc, but this is just fo rlearning

//Constructor 
  public MyCLass()
        {
            InitializeComponent();
            OverlayRectangle;

        }


//function that creates a rectange
        void OverlayRectangle()
        {
            Rectangle rect = new Rectangle();
            rect.Width = 200;
            rect.Height = 100;
        }


//user click on button to capture a photo code

                 //Pick a image
                 var options = new MediaPickerOptions
                {
                    Title = "Please select a Image"
                };
                var result = await MediaPicker.CapturePhotoAsync(options);

                if (result != null)
                {
                    //crop image
                    var stream = await result.OpenReadAsync();
                    using (var newImage = await CrossImageEdit.Current.CreateImageAsync(GetImageStreamAsBytes(stream)))
                    {
                        var croped = await Task.Run(() =>
                                newImage.Crop(10, 20, 250, 100)
                                     .Rotate(180)
                                     .Resize(100, 0)
                                     .ToPng()
                    );

                        //display
                        ImagePage1.Source = ImageSource.FromStream(() => new MemoryStream(croped));
                    }
                }
Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2021-05-12T02:42:36.77+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    how can I over lay a rectangle ontop of MediaPicke

    Do you mean adding a overlay when taking the photo? It's not possible because the caputre function uses the native Camera and the API doesn't exist as we launch the camera app. Xamarin.Essentials.MediaPicker is derived from media plugin.

    Related link:
    https://github.com/jamesmontemagno/MediaPlugin/issues/621

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.