Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

The parameters to modify the size of the image are not working in android #553

Closed
epinorodriguez opened this issue May 25, 2018 · 3 comments

Comments

@epinorodriguez
Copy link

epinorodriguez commented May 25, 2018

the method is not changing the size of the image using the available parameters,

Bug Information

Version Number of Plugin: 4.0.0.9
Device Tested On: Motorola Z2 Play
Simulator Tested On:
Version of VS: 15.7.1
Version of Xamarin: 3.0.0.482510
Versions of other things you are using:

Steps to reproduce the Behavior

Using CrossMedia.Current.TakePhotoAsync() method is saving the image in max quality and max size without taken effect any of the options

Expected Behavior

image should get resized

Actual Behavior

the parameters to resize the image are not working

Code snippet

var foto = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions() { SaveToAlbum = true, PhotoSize = Plugin.Media.Abstractions.PhotoSize.MaxWidthHeight, SaveMetaData = false, MaxWidthHeight = 800, });

@pspeybro
Copy link

I am also in need of the MaxWidtHeight functionality, so I had a look in the code to see if this was implemented.

There seems to be some code missing in a certain code path, both for PickMediaAsync and TakeMediaAsync:

if (options.RotateImage)
{
      await FixOrientationAndResizeAsync(media.Path, options, originalMetadata);
}
else
{
      await ResizeAsync(media.Path, options.PhotoSize, options.CompressionQuality, options.CustomPhotoSize, originalMetadata);
}

The FixOrientationAndResizeAsync seems to have an implementation for MaxWidthHeight, but the ResizeAsync is missing this logic.

Specifically this part seems to be missing in de ResizeAsync:

if (mediaOptions.PhotoSize == PhotoSize.MaxWidthHeight && mediaOptions.MaxWidthHeight.HasValue)
 {
     var max = Math.Max(options.OutWidth, options.OutHeight);
     if (max > mediaOptions.MaxWidthHeight)
     {
          percent = (float)mediaOptions.MaxWidthHeight / (float)max;
      }
}

I just did a quick test with current version of nuget package 4.0.0.9, and if I set RotateImage = true, the resizing works. If I set RotateImage = false, it fails to resize the image.

@beeradmoore
Copy link

beeradmoore commented Dec 14, 2018

They also don't seem to be working on iOS. I'm going to have a crack and it and see if I can find why.

EDIT: I've tried adding the projects csporj to my Xamarin.Forms project, couldn't compile even targeting iOS because it hates the Android support libraries this brings in. Tried directly in iOS app, same issues. Tried even running the Media.sln to try build a dll and I get a whole bunch of

/git/MediaPlugin/src/Media.Plugin/Media.Plugin.csproj: Error NU1202: Package Xamarin.Android.Support.Core.Utils 25.4.0.2 is not compatible with netstandard1.0 (.NETStandard,Version=v1.0). Package Xamarin.Android.Support.Core.Utils 25.4.0.2 supports: monoandroid70 (MonoAndroid,Version=v7.0) (NU1202) (Media.Plugin)

I'm more than happy to look into and try fix these issues for iOS and Android as I've done a heap of image processing on them both natively, but I have no idea of how to even run this project to get started :(

@jamesmontemagno
Copy link
Owner

Fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants