Open Brosten opened 3 years ago
It's definitely not in my plans. But if someone does I won't mind. Unfortunately I don't have much time. And I have to get my priorities right I plan to make previews of images and video files
While we are at it, getting it rotated to the origin set in the exif info wouldn't hurt. Currently I borrowed some code from here https://stackoverflow.com/questions/44181914/iphone-image-orientation-wrong-when-resizing-with-skiasharp to do that stuff.
Do you have problems with origin image rotation in this plugin?
Well, it's not a huge problem. But if I just take the photo bytes and show it on screen, it might show with the wrong rotation. So... I'm rotating it myself, before I show it.
Perhaps some basic image manipulation of byte[] images could be something for the CommunityToolkit. Something like ResizeAndRotate(int MaxWidthOrHeight, int quality)
I had no problem with the rotated image. If you can provide a description of how to reproduce this. I'll try to fix it
I think it's camera app dependent. I'm using Piel 4 (Android) with default camera. Don't have time today to fix repo, but I'll try to fix one soon...
On my android (Pixel 4) the following code draws the image upside down.
`
<Image x:Name="theImage" HeightRequest="200" WidthRequest="200" />
</StackLayout>`
private async void Button_Clicked(object sender, EventArgs e) { var image = await NativeMedia.MediaGallery.PickAsync(types: NativeMedia.MediaFileType.Image); var file = image.Files.FirstOrDefault(); var stream = await file.OpenReadAsync(); theImage.Source = ImageSource.FromStream(() => stream); }
on iOS it doesn't rotate at all. And if trying to rotate with SkiaSharp, the codec will end up being null. This is not the case if using PickPhotoAsync from Xamarin.Essentials.
using (var inputStream = new SKManagedStream(stream));
using (var codec = SKCodec.Create(inputStream));
// Here codec is null for iOS, but not for android
@dimonovdd : Were you able to reproduce this?
Regarding what I wrote about codec being null for iOS, it seems to have been fixed in some way. At least it works fine for me in iOS as well now.
Width, Height, Quality and orientation are still things i'd like to see! =)
Width, Height, Quality and orientation are still things i'd like to see! =)
Do you have any ideas? how to implement it for all platforms? Have you tried using MetadataExtractor?
Hi guys, I recently came across your library and have started using it - great work thanks. I also had the issue, that a photo taken in landscape orientation would display on other operating systems in incorrect orientation. My scenario is that the image is picked and uploaded to a server, then the server uses the image in a DevExpress report, and hence renders into a final PDF with incorrect orientation. I also required max dimension, and quality level support, so I just applied that after the image was picked (caveat - it's iOS specific). The act of using the iOS APIs to re-encode an image, has the side effect of baking the orientation into the resultant image - hence it implicitly solves the orientation issue.
public static async Task<Stream> OpenReadAsync(IMediaFile mediaFile)
{
using (var imageData = NSData.FromStream(await mediaFile.OpenReadAsync()))
using (var image = UIImage.LoadFromData(imageData))
{
// load image
using (var resized = image.ResizeImage(800, float.MaxValue))
{
return resized.AsJPEG(0.25f).AsStream();
}
}
}
@Adam-Langley Hi. You can create a PR. But keep in mind that using UIImage
, we lose metadata.
I could sure use the compression of CrossMedia.Current.PickPhotoAsync that I used with Xamarin. I am using MediaGallery in Maui but the photos on iOS are about 10x larger than they need to be and cause my data files to be huge.
If the CrossMedia code were available on github I would be tempted to try and port the compression feature to the MediaGallery repo. I don't see it though. Can someone point it out?
Summary
When using the legacy CrossMedia plugin, you have the ability to define image max width/height and compressionQuality. Are there any plans to implement this kind of functionality?
API Changes
Perhaps looking at CrossMedia.Current.PickPhotoAsync could give some inspiration