Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] UWP Media Picker capture Photo doesn't work on windows 11 #2112

Open
DaniRvd opened this issue Dec 4, 2023 · 7 comments
Open

[Bug] UWP Media Picker capture Photo doesn't work on windows 11 #2112

DaniRvd opened this issue Dec 4, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@DaniRvd
Copy link

DaniRvd commented Dec 4, 2023

Description

OS : Windows 11 Enterprise
OS build: 22621.2715
Starting with 2311 camera update, is not possible to take picture with Xamarin Essential Media Picker

Steps to Reproduce

  1. Open the sample app
  2. Press take Photo button
  3. Thy to capture a photo
  4. An error will be displayed

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue:

  • Last known good version:

  • IDE: Visual studio

  • Platform Target Frameworks:

    • UWP: Min version Windows 10 16299, Target Version Windows 11 22621
  • Nuget Packages:
    First test:
    image

Second test
Xamarin Forms: latest
Xamarin Essentials: latest

  • Affected Devices:
    Windows 11 devices

Screenshots

  1. Open the sample App, then press TakePhoto button.
    image
  2. Press take photo button on the camera app, then following error will appear
    image

Reproduction Link

XamarinEsenstialSample.zip

@DaniRvd DaniRvd added the bug Something isn't working label Dec 4, 2023
@z0mero
Copy link

z0mero commented Dec 4, 2023

Hello Sir, i also have the same problem but i didn't find a workaround for this issue yet. Please let me know if you find any solution!

@denisdnl
Copy link

denisdnl commented Dec 4, 2023

I went into the same problem. Didn't find any solution.

@DaniRvd
Copy link
Author

DaniRvd commented Dec 8, 2023

Manage pass over the issue described above.
But now I have another issue on UWP when my app is running on Windows 11 platform. Because
Did some debugging on the Xamarin Essentials sample code. and the issue is caused by the setting form picture bellow, because you cannot save the unstill you make some editing, and if you press the save a copy button then the image cannot be loaded to the app anymore.
image

My question is if you can expose AllowCropping setting int the MediaPickerOptions this way the this setting can be disabled and MediaPicker will work again as expected.

This issue can be closed I'll open a new one and complete all the details needed

@thomasphillipsgb
Copy link

Encountering this issue too, in regard to the cropper not allowing to save without editing, though i'm not seeing the code mentioned here

Manage pass over the issue described above. But now I have another issue on UWP when my app is running on Windows 11 platform. Because Did some debugging on the Xamarin Essentials sample code. and the issue is caused by the setting form picture bellow, because you cannot save the unstill you make some editing, and if you press the save a copy button then the image cannot be loaded to the app anymore. image

My question is if you can expose AllowCropping setting int the MediaPickerOptions this way the this setting can be disabled and MediaPicker will work again as expected.

This issue can be closed I'll open a new one and complete all the details needed

or is it the fact that AllowCropping is set to true by default?
I believe this to be the line in question

captureUi.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

@DaniRvd
Copy link
Author

DaniRvd commented Jan 12, 2024

The issue is indeed the AllowCropping is set by default on true, this setting should be exposed and make it available to the developer.
But seems nobody from Xamarin Essentials read this

@gdougherty-cbt
Copy link

Are there any updates on this? It seems like it should be a relatively simple fix to expose the property or disable clipping since it doesn't seem to work as a feature in that context in general.

@gdougherty-cbt
Copy link

For anyone that needs a workaround, adding this method to a helper on your UWP project and calling it via the dependency service works.

    public async Task<(FileResult, byte[])> CaptureAsync(MediaPickerOptions options, bool photo)
    {
        // This is largely taken from the following file to get around the following issue
        // https://github.com/xamarin/Essentials/blob/ae2cb946f8215ff49fa20773ec824b317e6ca603/Xamarin.Essentials/MediaPicker/MediaPicker.uwp.cs
        // https://github.com/xamarin/Essentials/issues/2112
        var captureUi = new CameraCaptureUI();

        if (photo)
        {
            captureUi.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUi.PhotoSettings.AllowCropping = false;
        }
        else
        {
            captureUi.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
        }

        var file = await captureUi.CaptureFileAsync(photo ? CameraCaptureUIMode.Photo : CameraCaptureUIMode.Video);
        // I'm not 100% sure why but assume it's related to local extension methods I don't have access to, but I cannot send the file as an argument to the file result.
        //      We still can use it's file name handling here, etc., but the OpenReadAsync on the FileResult object created below does not work.
        //      Pulling the full image early here lets us work around this issue.
        if (file != null)
        {
            using (var ms = new MemoryStream())
            {
                using (var s = await file.OpenReadAsync())
                {
                    s.AsStreamForRead().CopyTo(ms);
                    return (new FileResult(file.Path, file.ContentType), ms.ToArray());
                }
            }
        }

        return (null, null);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants