MediaPlugin: Unable to check orientation: Java.Lang.NullPointerException
Bug Information
Calling CrossMedia.Current.TakePhotoAsync causes exception Unable to check orientation: Java.Lang.NullPointerException
Version Number of Plugin: 3.0.1 Device Tested On: Samsung J5, Android 6.0 Version of VS: 2017, version 15.3.5 Version of Xamarin: Xamarin forms 2.4.0.283 Versions of other things you are using: Xamarin.FFImageLoading.Forms 2.2.20
Steps to reproduce the Behavior
Put the phone down on a flat surface and take a photo with camera. Accept photo
Expected Behavior
return a black photo, as shown in the camera preview
Actual Behavior
return a file, that when trying to load cases invalid file format exception
Unable to check orientation: Java.Lang.NullPointerException: Attempt to get length of null array Unable to check orientation: Java.Lang.NullPointerException: Attempt to get length of null array 10-12 14:33:51.411 I/mono-stdout(16474): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <e499a5498b1b48379b88fe5ed629079f>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <e499a5498b1b48379b88fe5ed629079f>:0 at Android.Media.ExifInterface.SaveAttributes () [0x0000a] in <2e14bb2dd93a405e81838369ed72695b>:0 at Plugin.Media.MediaImplementation+<TakePhotoAsync>d__16.MoveNext () [0x000b2] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:556 --- End of managed Java.Lang.NullPointerException stack trace ---
Code snippet
` await CrossMedia.Current.Initialize();
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
MaxWidthHeight = 500,
PhotoSize = PhotoSize.MaxWidthHeight,
CompressionQuality = 80
});
//Exception Unable to check orientation is shown in log
Func<CancellationToken, Task<Stream>> fs = (t) => Task.Run(() => file.GetStream());
var jpegstream = ImageService.Instance.LoadStream(fs).AsJPGStreamAsync();
//This line crashes with System.BadImageFormatException: Bad image format
var s = await jpegstream;`
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Fixes #367 to ensure exif info is valid sometimes thumbnail may say it exists, but it doesn't so can't resave as file will be curropted. — committed to jamesmontemagno/MediaPlugin by jamesmontemagno 7 years ago
- try catch getting exif for android #367 — committed to jamesmontemagno/MediaPlugin by jamesmontemagno 7 years ago
Thanks. Happy to help. Tested and confirm that it is now working as expected.
@prashantvc can you validate?