From: tscholb Date: Fri, 29 Jan 2021 08:37:53 +0000 (+0900) Subject: [NUI] Add GetOriginalImageSize() considering rotation (#2587) X-Git-Tag: submit/tizen_6.0/20210129.175201~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6862c0c72bdfd36d5f5de9d9570a6588bd99ecbc;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add GetOriginalImageSize() considering rotation (#2587) --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.ImageLoading.cs b/src/Tizen.NUI/src/internal/Interop/Interop.ImageLoading.cs index f599a373f..2f5b70d8b 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.ImageLoading.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.ImageLoading.cs @@ -38,8 +38,11 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetClosestImageSize__SWIG_4")] public static extern global::System.IntPtr GetClosestImageSize__SWIG_4(string jarg1); - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetOriginalImageSize")] - public static extern global::System.IntPtr GetOriginalImageSize(string jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetOriginalImageSize__SWIG_0")] + public static extern global::System.IntPtr GetOriginalImageSize_SWIG_0(string jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetOriginalImageSize__SWIG_1")] + public static extern global::System.IntPtr GetOriginalImageSize_SWIG_1(string jarg1, bool jarg2); [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DownloadImageSynchronously__SWIG_0")] public static extern global::System.IntPtr DownloadImageSynchronously__SWIG_0(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, int jarg3, int jarg4, bool jarg5); diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 520424728..565b1af9d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -1135,10 +1135,23 @@ namespace Tizen.NUI.BaseComponents { if(_resourceUrl != null) { - Size2D desiredSize = new Size2D(_desired_width,_desired_height); - Size2D imageSize = ImageLoading.GetClosestImageSize(_resourceUrl, desiredSize, FittingModeType.ScaleToFill); - temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue((int)imageSize.Width)); - temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue((int)imageSize.Height)); + Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl,true); + + int adjustedDesiredWidth, adjustedDesiredHeight; + float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width; + float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width; + if( aspectOfImageSize > aspectOfDesiredSize) + { + adjustedDesiredWidth = _desired_width; + adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width; + } + else + { + adjustedDesiredWidth = imageSize.Width * _desired_height/ imageSize.Height; + adjustedDesiredHeight = _desired_height; + } + temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue(adjustedDesiredWidth)); + temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue(adjustedDesiredHeight)); temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int) FittingModeType.ScaleToFill)); } } diff --git a/src/Tizen.NUI/src/public/ImageLoading.cs b/src/Tizen.NUI/src/public/ImageLoading.cs index 6de37ca22..58728fd80 100755 --- a/src/Tizen.NUI/src/public/ImageLoading.cs +++ b/src/Tizen.NUI/src/public/ImageLoading.cs @@ -211,7 +211,7 @@ namespace Tizen.NUI } /// - /// Get the size of an original image + /// Get the size of an original image. this method will not respect any rotation of image /// /// The name of the image. /// Dimension of the original image. @@ -220,7 +220,24 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public static Size2D GetOriginalImageSize(string filename) { - var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize(filename), true); + var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize_SWIG_0(filename), true); + Size2D ret = new Size2D(val.GetWidth(), val.GetHeight()); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Get the size of an original image consider rotation + /// + /// The name of the image. + /// Reorient the image to respect any orientation metadata in its header. + /// Dimension of the original image. + /// 6 + /// This will be released at Tizen.NET API Level 9. Therefore, currently this would be used as an in-house API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static Size2D GetOriginalImageSize(string filename, bool orientationCorrection ) + { + var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize_SWIG_1(filename,orientationCorrection), true); Size2D ret = new Size2D(val.GetWidth(), val.GetHeight()); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret;