当前位置: 首页>>代码示例>>C#>>正文


C# ScaleMode.ToString方法代码示例

本文整理汇总了C#中ScaleMode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ScaleMode.ToString方法的具体用法?C# ScaleMode.ToString怎么用?C# ScaleMode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScaleMode的用法示例。


在下文中一共展示了ScaleMode.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ScaleFromTo

        /**
        * <summary>
        * Returns the scaling vector needed to go from one vector to another vector. Optionally provide a ScaleMode to determine
        * how the scaling should be performed. If attempting to find the scale results in an infinity or NAN result, Vector3.zero
        * will be returned.
        * </summary>
        */
        public static Vector3 ScaleFromTo(Vector3 from, Vector3 to, ScaleMode scaleMode = ScaleMode.StretchToFill)
        {
            Vector3 scale = Vector3.one;
            scale.x = to.x / from.x;
            scale.y = to.y / from.y;
            scale.z = to.z / from.z;

            Func<float, bool> isInvalid = (value) => { return float.IsInfinity(value) || float.IsNaN(value); };
            if (isInvalid(scale.x) || isInvalid(scale.y) || isInvalid(scale.z))
                return Vector3.zero;

            switch (scaleMode) {
            case ScaleMode.ScaleAndCrop:
                scale.x = scale.y = scale.z = Mathf.Max(scale.x, scale.y);
                break;

            case ScaleMode.ScaleToFit:
                scale.x = scale.y = scale.z = Mathf.Min(scale.x, scale.y);
                break;

            case ScaleMode.StretchToFill:
                //Do nothing
                break;

            default:
                Debug.LogException(new System.NotImplementedException("The Received ScaleMode." + scaleMode.ToString() + " is not implemented."));
                break;
            }

            return scale;
        }
开发者ID:JaySoyer,项目名称:Unity-Utils,代码行数:38,代码来源:Vectors.cs

示例2: Fit

        /// <summary>
        /// Fits the specified image to the supplied max width and height.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="maxWidth">Width of the max.</param>
        /// <param name="maxHeight">Height of the max.</param>
        /// <param name="fitMode">The fit mode.</param>
        /// <param name="scaleMode">The scale mode.</param>
        /// <param name="alignMode">The align mode.</param>
        /// <param name="format">The format.</param>
        /// <param name="quality">The quality.</param>
        /// <param name="colors">The colors.</param>
        /// <param name="bgColor">Color of the background.</param>
        /// <returns></returns>
        public static IFilteredImage Fit(this IFilteredImage image, int maxWidth, int maxHeight, 
            FitMode fitMode = FitMode.Pad, ScaleMode scaleMode = ScaleMode.Down,
            AlignMode alignMode = AlignMode.MiddleCenter, ImageFormat format = ImageFormat.Auto,
            int quality = 90, int colors = 256, string bgColor = "")
        {
            image.Filters.Add("w", maxWidth);
            image.Filters.Add("h", maxHeight);

            if(fitMode != FitMode.Pad)
                image.Filters.Add("mode", fitMode.ToString().ToLower());

            if(scaleMode != ScaleMode.Down)
                image.Filters.Add("scale", scaleMode.ToString().ToLower());

            if(alignMode != AlignMode.MiddleCenter)
                image.Filters.Add("anchor", alignMode.ToString().ToLower());

            if(format != ImageFormat.Auto)
                image.Filters.Add("format", format.ToString().ToLower());

            if(quality != 90)
                image.Filters.Add("quality", Math.Min(100, Math.Max(0, quality)));

            if (colors != 256)
                image.Filters.Add("colors", Math.Min(256, Math.Max(2, quality)));

            if (!string.IsNullOrEmpty(bgColor))
                image.Filters.Add("bgcolor", bgColor);

            return image;
        }
开发者ID:TSalaam,项目名称:karbon-cms,代码行数:45,代码来源:FileApiExtensions.cs


注:本文中的ScaleMode.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。