Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

[Bug][iOS] Stream length from captured photo is larger than stream length from photo from camera

Open JanMatuszny opened this issue 4 years ago • 11 comments

Description

I get FileResult from MediaPicker.CapturePhotoAsync and then I use OpenReadAsync to get stream from file. This stream has ~10mb, but when i use camera on the same iPhone i'm getting photo with ~2.5mb.

Expected Behaviour

The file should have the same size like file from camera.

Actual Behaviour

The file has size ~4 times larger than file from camera.

Basic Information

  • Version with issue: 1.6.1
  • IDE: Rider 2020.2.3
  • Platform Target Frameworks:
    • iOS: 14.4
  • Nuget Packages: Xamarin.Forms 4.6.0.800
  • Affected Devices: iPhone 5s, iPhone 11 Pro Max

JanMatuszny avatar Feb 22 '21 15:02 JanMatuszny

@JanMatuszny I am also facing the same issue.

gisongeorge avatar Mar 03 '21 07:03 gisongeorge

This is because for some reason on iOS the Xamarin.Essentials MediaPicker processes images from the camera as PNG, which is highly inefficient for photographs and more meant for screenshots and website assets etc. https://github.com/xamarin/Essentials/blob/7218ab88f7fbe00ec3379bd54e6c0ce35ffc0c22/Xamarin.Essentials/FileSystem/FileSystem.ios.cs#L195

I've created PR #1747 to fix this behaviour. Hopefully it gets merged.

leonluc-dev avatar Apr 08 '21 10:04 leonluc-dev

This is quite a nasty one. What's stopping the PR from getting merged and a fix released?

MitchBomcanhao avatar Aug 03 '21 13:08 MitchBomcanhao

I am also facing the same issue. I can see there's some errors because of which merging is blocked. If this isn't done in time, would have to switch to using the MediaPlugin to capture photos from camera.

pratikarya avatar Aug 09 '21 10:08 pratikarya

Have switched back to using MediaPlugin temporarily until this has been fixed.

pratikarya avatar Aug 24 '21 10:08 pratikarya

I've kept the essentials stuff but made a custom implementation for the ios camera action. Would be great to get this fixed, though...

MitchBomcanhao avatar Aug 25 '21 19:08 MitchBomcanhao

for completeness, this is a pretty good starting point to make your own variant of the iOS take photo action, while keeping xamarin essentials for the other platforms. https://github.com/xamarin/Essentials/issues/1514#issuecomment-874148026

MitchBomcanhao avatar Aug 26 '21 10:08 MitchBomcanhao

The newer code in .net maui still appears to have the same fault (see https://github.com/dotnet/maui/blob/main/src/Essentials/src/FileSystem/FileSystem.ios.cs

MitchBomcanhao avatar May 03 '22 15:05 MitchBomcanhao

Is there any way of using fixed code (injecting somehow custom implementation)? Or any reasonable workaround for this?

tomaszras-intive avatar Feb 06 '24 15:02 tomaszras-intive

@tomaszras-intive did you read the comments above

MitchBomcanhao avatar Feb 06 '24 15:02 MitchBomcanhao

Sorry, I just did quick scrolling. Found some workaround in link that you posted (#1514) , Thanks!

tomaszras-intive avatar Feb 06 '24 19:02 tomaszras-intive