I'm using James Montemagno´s media plugin to take photos.
For some reason, and only when running the application on my phone, when taking photos, thumbnails do appear correctly in TestFolder, but they appear as empty files.
Images appear correctly when running in the emulator.
This is my code:
public async Task<MediaFile> TakePhoto() {
MediaFile result = null;
await CrossMedia.Current.Initialize();
if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported) {
// Supply media options for saving our photo after it's taken.
var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions {
SaveToAlbum = true,
Directory = "TestFolder",
Name="test.jpg"
};
// Take a photo of the business receipt.
result = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
}
return result;
}
Edit 1:
In short, for some reason the Media plugin doesn't work on my phone (Huawei P8 Lite). I've tried the sample on GitHub: (Usage)
https://github.com/jamesmontemagno/MediaPlugin
Photos do show in the emulator but don't on the phone (the camera opens and takes photos). As I mentioned above, if I access the album folder empty thumbnails appear.
Edit 2
This is the android manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="15" />
<application android:label="MediaPluginTests.Droid"></application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>
Also I've added:
var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted) {
var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });
cameraStatus = results[Permission.Camera];
storageStatus = results[Permission.Storage];
}
Both permissions return as granted.
Edit 3
I've tried on a Samsung Galaxy A3 and works perfectly, shows correctly in the camera roll and the app.
But this how images appear on my Huawei P8 phone's camera roll album:
Edit 4
I have tried on a different Huawei P8 Device and am getting the same problem.
To solve the problem I set:
PhotoSize = PhotoSize.Small
On StoreCameraMediaOptions:
var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions {
SaveToAlbum = true,
Directory = "MyDirectory",
PhotoSize = PhotoSize.Small
};
But instead of binding to AlbumPath I bind to Path:
Property from ViewModel(Using PRISM for Xamarin Forms):
public MediaFile Photo {
get {
return photo;
}
set {
SetProperty<MediaFile>(ref photo, value);
}
}
<Image Grid.Row="0" Grid.ColumnSpan="2" Source="{Binding Photo.Path}"></Image>
I realised that if I added a Delay after the photo was taken:
await Task.Delay(5000)
Images would start to appear in the camera roll folder, but even then, the image didn't show on screen.
After looking at the output screen in Visual Studio, I noticed this message:
03-14 10:52:51.808 W/OpenGLRenderer(18106): Bitmap too large to be uploaded into a texture (3120x4160, max=4096x4096)
I then realised that the problem was related to image size, but even setting the image size to small on StoreCameraMediaOptions , it made no difference.
It seems that resizing only applies to the internal application storage image and not the one stored in the camera roll folder.
Once the image is resized the photo shows correctly in the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With