Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Capture photo using plug in media shows screen as colored retangles

pearlshwetapearlshweta Member ✭✭

Hello,
i am trying to capture the photo using Media plugin. But the image captured shows colored rectangles as attached image.
Can you please help me?
Thanks in advance.

The button click for the photo capture is

if (brepeat == false)
{
await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsTakePhotoSupported && !CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("Error", "Photo Capture and pick not supported", "OK");
                return;
            }

            var varFilePhoto = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions()
            {
                                    Name = "Img" + DateTime.Now.ToString() + ".jpg"
            }); ;


            if (varFilePhoto == null)
                return;

            lblPath.Text = varFilePhoto.Path;
            imgCapture.Source = ImageSource.FromStream(() => {
                return varFilePhoto.GetStream();
            });
        }

        brepeat = true;

MainActivity.cs is

protected override async void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);
        await CrossMedia.Current.Initialize();

        int requestPermissions = 1;
        string cameraPermission = Android.Manifest.Permission.Camera;

        if (!(ContextCompat.CheckSelfPermission(this, cameraPermission) == (int)Permission.Granted))
        {
            ActivityCompat.RequestPermissions(this, new String[] { cameraPermission, }, requestPermissions);
        }

        CrossCurrentActivity.Current.Init(this, savedInstanceState);
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

Android Manifest is

<?xml version="1.0" encoding="utf-8"?>



        <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
               android:resource="@xml/file_paths"></meta-data>
    </provider>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_INPUT_STATE" />

Best Answer

Answers

Sign In or Register to comment.