Forum Libraries, Components, and Plugins


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.

Xamarin.Plugin.Media - Camera not respond at first use

Franck_SDEAFranck_SDEA Member ✭✭


I use Xamarin.Plugin.Media for QR Code scan. In first launch, the app request authorization for camera, but after acceptance, the camera view does not activate, the view remains white.

Permissions in AssemblyInfo:
[assembly: UsesPermission(Android.Manifest.Permission.Camera)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
[assembly: UsesFeature("", Required = true)]
[assembly: UsesFeature("", Required = true)]
[assembly: UsesFeature("", Required = true)]

await CrossMedia.Current.Initialize();

if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
    await DisplayAlert("Erreur caméra...", "Aucune caméra disponible !", "OK");

var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
    SaveToAlbum = false,
    PhotoSize = PhotoSize.Medium,
    CompressionQuality = 25,
    Name = "SDEA_SSO_IMG_" + this.QrCodeValues[1].Substring(this.QrCodeValues[1].Length - 8, 8) + ".jpg"

if (file == null)
    await DisplayAlert("Erreur photo...", "Une erreur est survenue lors de la prise ou l'enregistrement de la photo !", "OK");
    /* Stock le chemin de la phoho dans le bouton. */
    img.PhotoFilename = file.Path;

    /* Création d'une miniature de la photo pour le bouton */
    byte[] imageData;
    Stream stream = file.GetStream();

    using (MemoryStream ms = new MemoryStream())
        imageData = ms.ToArray();

    byte[] resizedImage = await ImageResizer.ResizeImage(imageData, 75, 75);
    img.Source = ImageSource.FromStream(() => new MemoryStream(resizedImage));

Thanks ;)


Sign In or Register to comment.