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


C# WebImage.Clone方法代码示例

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


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

示例1: GalleryImage

        public static MvcHtmlString GalleryImage(this HtmlHelper helper, string galleryImage) {
            if (string.IsNullOrEmpty(galleryImage))
                return MvcHtmlString.Empty;

            var url = new UrlHelper(helper.ViewContext.RequestContext);
            var path = "~/public/UserFiles/gallery/" + HttpUtility.JavaScriptStringEncode(galleryImage);

            galleryImage = url.Content(path);

            if (galleryImage.EndsWith(".swf", StringComparison.OrdinalIgnoreCase))
                return MvcHtmlString.Create(string.Format("<embed wmode='opaque' style='display: block' width='512' height='300' src='{0}'></embed>", galleryImage));

            lock (lockObject) {
                var image = new WebImage(path);

                if (image.Width > 512 || image.Height > 300) {
                    var newImage = image.Clone();

                    newImage.Resize(512, 300);

                    if (newImage.Height < 300) {
                        image.Resize(image.Width, 300);
                    }
                    else {
                        image.Resize(512, image.Height);
                    }

                    image.Save();
                }
            }

            return MvcHtmlString.Create(string.Format("<div class='gallery-image' style=\"background-image: url('{0}')\"></div>", galleryImage));


        }
开发者ID:Avimunk,项目名称:soglowek.tmgroup,代码行数:35,代码来源:ApplicationHelper.cs

示例2: AddImageWatermark

        /// <summary>
        /// Adds image watermark to an image.
        /// </summary>
        /// <param name="watermarkImage">Image to use as a watermark.</param>
        /// <param name="width">Width of watermark.</param>
        /// <param name="height">Height of watermark.</param>
        /// <param name="horizontalAlign">Horizontal alignment for watermark image. Can be "right", "left", or "center".</param>
        /// <param name="verticalAlign">Vertical alignment for watermark image. Can be "top", "bottom", or "middle".</param>
        /// <param name="opacity">Watermark text opacity. Should be between 0 and 100.</param>
        /// <param name="padding">Size of padding around watermark image in pixels.</param>
        /// <returns>Modified WebImage instance with added watermark.</returns>
        public WebImage AddImageWatermark(
            WebImage watermarkImage,
            int width = 0,
            int height = 0,
            string horizontalAlign = "Right",
            string verticalAlign = "Bottom",
            int opacity = 100,
            int padding = 5) {

            if (watermarkImage == null) {
                throw new ArgumentNullException("watermarkImage");
            }

            if (width < 0) {
                throw new ArgumentOutOfRangeException(
                    "width",
                    String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }
            if (height < 0) {
                throw new ArgumentOutOfRangeException(
                    "height",
                    String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }
            if (((width == 0) && (height > 0)) || ((width > 0) && (height == 0))) {
                throw new ArgumentException(HelpersResources.WebImage_IncorrectWidthAndHeight);
            }
            if ((opacity < 0) || (opacity > 100)) {
                throw new ArgumentOutOfRangeException("opacity", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_Between, 0, 100));
            }

            HorizontalAlign horizontalAlignEnum = ParseHorizontalAlign(horizontalAlign);
            VerticalAlign verticalAlignEnum = ParseVerticalAlign(verticalAlign);

            if (padding < 0) {
                throw new ArgumentOutOfRangeException(
                    "padding",
                    String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }

            WatermarkImageTransformation transformation =
                new WatermarkImageTransformation(watermarkImage.Clone(), width, height, horizontalAlignEnum, verticalAlignEnum, opacity, padding);
            _transformations.Add(transformation);
            return this;
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:55,代码来源:WebImage.cs

示例3: Resize

 /// <summary>
 /// Resizes the specified image.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="format">The format.</param>
 /// <param name="path">The path.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="aspect">if set to <c>true</c> [aspect].</param>
 private static void Resize(WebImage image, string format, string path, int width, int height, bool aspect)
 {
     image.Clone().Resize(width, height, aspect).Save(path.AsPath(), format);
 }
开发者ID:Mike343,项目名称:Netcoders,代码行数:13,代码来源:ImageService.cs


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