手机图片库中的图片尺寸错误

时间:2019-01-02 08:33:33

标签: xamarin xamarin.forms

在我的应用程序中,我使用Xam.Media.Plugin(来自J.Montemagno)从图库中选择图像,或使用手机通过PopUp进行拍摄。问题是,如果我从图库中选择由Phone拍摄的图像,则会尊重图片的尺寸;相反,如果我从画廊中选择从网上下载的照片,则照片的尺寸将不被尊重。

一些示例:我下载了正方形图片600x600 px,但是如果选择它,我会在显示器上看到或多或少的正方形图片200x200 px.与矩形图像1920x1080( FHD)图像等。相反,如果我拍张照片(4:3或16:9相同),则会尊重尺寸。

此外,如果我尝试将流放入Image中,然后将其设置为HeightRequest,WidthRequest,Xamarin,请忽略我的命令,而我仍然会看到图片的尺寸错误。

有人可以帮助我吗? THX

[...]
private async void BtnFoto_Clicked(object sender, EventArgs e)
    {           
        var action = await DisplayActionSheet("Choose your Photo", "Back", "", "Gallery", "Take Photo");
        switch (action)
        {
            #region Gallery
            case "Gallery":

                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Alert", "Function not supported", "OK");
                    return;
                }
                else
                {
                    var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
                    {                            
                        CompressionQuality = 75,
                        CustomPhotoSize = 50,
                        PhotoSize = PhotoSize.MaxWidthHeight, //!!!not working!!!
                        MaxWidthHeight = 2000,
                    }
                    );

                    if (file == null)
                    {
                        return;
                    }

                    else
                    {


                        App.pickedImage.Source = ImageSource.FromStream(() => file.GetStream());
//some translation that I need, not important for the problem
                        App.pickedImage.TranslationY = 168; //misureGriglia.Height
                        App.pickedImage.TranslationX = 40; //misureGriglia.Width
                        App.pickedImage.MinimumHeightRequest = 280;//!!!not working!!!
                        App.pickedImage.MinimumWidthRequest = 280;//!!!not working!!!

                    }
                }
                break;
            #endregion

            #region TakePhoto
            case "Take Photo": 

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("Alert", "Camera not suitable", "OK");
                    return;
                }

                var file2 = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Test",
                    SaveToAlbum = true,
                    CompressionQuality = 75,
                    CustomPhotoSize = 50,
                    PhotoSize = PhotoSize.MaxWidthHeight,
                    MaxWidthHeight = 2000,
                    DefaultCamera = CameraDevice.Front
                });

                if (file2 == null)
                    return;
                else
                {

                    App.pickedImage.Source = ImageSource.FromStream(() => file2.GetStream());
//some translation that I need, not important for the problem
                    App.pickedImage.TranslationY = 168; //misureGriglia.Height
                    App.pickedImage.TranslationX = 40; //misureGriglia.Width


                }

                break;
                #endregion
        }
        await Navigation.PushAsync(new ResizeFoto());
    }

0 个答案:

没有答案