Пример #1
0
        private static PHImageContentMode ImageResizeAspectToPH(MediaFileGetImageOptions.ImageResizeAspect resizeAspect)
        {
            switch (resizeAspect)
            {
            case MediaFileGetImageOptions.ImageResizeAspect.AspectFill:
                return(PHImageContentMode.AspectFill);

            case MediaFileGetImageOptions.ImageResizeAspect.AspectFit:
                return(PHImageContentMode.AspectFit);

            default:
                return(PHImageContentMode.Default);
            }
        }
Пример #2
0
        private static void GetResizeDimensions(float origWidth, float origHeight, float destWidth, float destHeight, MediaFileGetImageOptions.ImageResizeAspect resizeAspect, out float resWidth, out float resHeight, out float x, out float y, out float width, out float height)
        {
            switch (resizeAspect)
            {
            case MediaFileGetImageOptions.ImageResizeAspect.AspectFill:
            case MediaFileGetImageOptions.ImageResizeAspect.AspectFit:

                resHeight = origHeight * destWidth / origWidth;
                resWidth  = destWidth;

                if (resizeAspect == MediaFileGetImageOptions.ImageResizeAspect.AspectFit)
                {
                    if (resHeight > destHeight)
                    {
                        resHeight = destHeight;
                        resWidth  = origWidth * destHeight / origHeight;
                    }

                    width  = resWidth;
                    height = resHeight;
                    x      = 0;
                    y      = 0;
                }
                else
                {
                    if (resHeight < destHeight)
                    {
                        resHeight = destHeight;
                        resWidth  = origWidth * destHeight / origHeight;
                    }

                    width  = destWidth;
                    height = destHeight;
                    x      = (resWidth - width) / 2;
                    y      = (resHeight - height) / 2;
                }

                break;

            default:
                x         = 0;
                y         = 0;
                width     = destWidth;
                height    = destHeight;
                resWidth  = destWidth;
                resHeight = destHeight;
                break;
            }
        }