dimonovdd / Xamarin.MediaGallery

This plugin is designed to picking and save images and video files from native gallery of Android and iOS devices and capture photos
MIT License
154 stars 19 forks source link

Setting size and quality options when picking #25

Open Brosten opened 3 years ago

Brosten commented 3 years ago

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

dimonovdd commented 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

Brosten commented 3 years ago

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.

dimonovdd commented 3 years ago

Do you have problems with origin image rotation in this plugin?

Brosten commented 3 years ago

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)

dimonovdd commented 3 years ago

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

Brosten commented 3 years ago

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...

Brosten commented 3 years ago

On my android (Pixel 4) the following code draws the image upside down. `

Brosten commented 3 years ago

@dimonovdd : Were you able to reproduce this?

Brosten commented 3 years ago

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! =)

dimonovdd commented 3 years ago

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?

Adam-Langley commented 3 years ago

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();
          }
      }
  }
dimonovdd commented 3 years ago

@Adam-Langley Hi. You can create a PR. But keep in mind that using UIImage, we lose metadata.

cdavidyoung commented 1 year ago

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?

dimonovdd commented 1 year ago

https://github.com/jamesmontemagno/MediaPlugin