• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Resizing.ImageState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ImageResizer.Resizing.ImageState的典型用法代码示例。如果您正苦于以下问题:C# ImageState类的具体用法?C# ImageState怎么用?C# ImageState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ImageState类属于ImageResizer.Resizing命名空间,在下文中一共展示了ImageState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: LayoutImage

        protected override RequestedAction LayoutImage(ImageState s)
        {
            if (s.sourceBitmap == null) return RequestedAction.None;

            //Parse carve data bitmap
            if (!string.IsNullOrEmpty(s.settings["carve.data"])) {
                string[] parts = s.settings["carve.data"].Split('|');
                //Parse block count and string
                var block_count = int.Parse(parts[0]);
                var carveString = new LzwDecoder("012").Decode(PathUtils.FromBase64UToBytes(parts[1]));

                float block_size = (int)Math.Floor(Math.Sqrt(s.originalSize.Width * s.originalSize.Height / (double)block_count));

                var carveData = new CarveDataPlotter() {
                    BlockCount=block_count,
                    Stride = (int)Math.Ceiling((float)s.originalSize.Width / block_size),
                    Rows = (int)Math.Ceiling((float)s.originalSize.Height / block_size)
                };

                carveData.Init(carveString);

                Size remove = carveData.GetRemovalSpace(s.originalSize.Width,s.originalSize.Height,(int)block_size);

                if (remove.Width / s.originalSize.Width > remove.Height / s.originalSize.Height) {
                    s.originalSize = new Size(s.originalSize.Width - remove.Width, s.originalSize.Height);
                } else {
                    s.originalSize = new Size(s.originalSize.Width, s.originalSize.Height - remove.Height);
                }

                //Save later
                s.Data[CarveData] = carveData;
            }

            return RequestedAction.None;
        }
开发者ID:kevjett,项目名称:Resizer,代码行数:35,代码来源:SeamCarvingPlugin.cs


示例2: PrepareDestinationBitmap

        protected override RequestedAction PrepareDestinationBitmap(ImageState s)
        {
            if (!this.IsDiagnosticRequest(s.settings)) return RequestedAction.None;

            // Rather than allow the normal process, we will throw an
            // AlternateResponseException that contains the data we *really*
            // want to return.
            var info = new LayoutInformation(s);
            var serializer = new JsonSerializer();

            // Check to see if indented JSON has been requested.  This is useful
            // for human-readable output.
            if (s.settings.Get("j.indented", false))
            {
                serializer.Formatting = Formatting.Indented;
            }

            serializer.Converters.Add(new InstructionsConverter());

            StringWriter sw = new StringWriter();
            serializer.Serialize(sw, info);
            var bytes = System.Text.Encoding.UTF8.GetBytes(sw.ToString());

            throw new AlternateResponseException(
                "Resizing pipeline was canceled as JSON data was requested instead.",
                "application/json; charset=utf-8",
                bytes);
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:28,代码来源:DiagnosticJsonPlugin.cs


示例3: LayoutImage

        protected override RequestedAction LayoutImage(ImageState s)
        {
            if (s.sourceBitmap == null) return RequestedAction.None;

            //percentpadding. Percentage is 0-100, multiplied by the average of the width and height.
            double percentpadding = s.settings.Get<double>("trim.percentpadding", 0) / 100;

            int? threshold = s.settings.Get<int>("trim.threshold");
            if (threshold != null) {
                if (threshold < 0) threshold = 0; if (threshold > 255) threshold = 255;

                Rectangle box = new BoundingBoxFinder().FindBoxSobel(s.sourceBitmap, new Rectangle(0, 0, s.sourceBitmap.Width, s.sourceBitmap.Height), (byte)threshold);
                //Add padding
                int paddingPixels = (int)Math.Ceiling(percentpadding * (box.Width + box.Height) / 2);
                box.X = Math.Max(0, box.X - paddingPixels);
                box.Y= Math.Max(0, box.Y - paddingPixels);
                box.Width = Math.Min(s.sourceBitmap.Width, box.Width + paddingPixels * 2);
                box.Height = Math.Min(s.sourceBitmap.Height, box.Height + paddingPixels * 2);

                //Adjust s.originalSize so the layout occurs properly.
                s.originalSize = box.Size;
                s.Data[RectDataKey] = box;
            }
            return RequestedAction.None;
        }
开发者ID:eakova,项目名称:resizer,代码行数:25,代码来源:WhitespaceTrimmerPlugin.cs


示例4: PostRenderImage

        protected override RequestedAction PostRenderImage(ImageState s)
        {
            var color = s.destBitmap.GetPixel(0,0);

            Console.WriteLine("PostLayoutEffects " + ++i + " color at (0,0): " + color);
            return base.PostRenderImage(s);
        }
开发者ID:fschwiet,项目名称:Gifenstein,代码行数:7,代码来源:NoopExtension.cs


示例5: PostRenderImage

        protected override RequestedAction PostRenderImage(ImageState s)
        {
            _delays = _delays ?? GetDelays(s.sourceBitmap);

            _visitor((Bitmap)s.destBitmap.Clone(), s.destGraphics, _delays[_visitIndex++]);

            return base.PostRenderImage(s);
        }
开发者ID:fschwiet,项目名称:Gifenstein,代码行数:8,代码来源:AnimationVisitorExtension.cs


示例6: GetOverlayParalellogram

        public PointF[] GetOverlayParalellogram(Overlay o, Size nativeSize, ImageState translateToFinalCoordinateSpace)
        {
            //What's the polygon w/h?
            double cw = PolygonMath.Dist(o.Poly[0], o.Poly[1]);
            double ch = PolygonMath.Dist(o.Poly[1], o.Poly[2]);
            //Take a copy to shrink to content size
            double w = cw;
            double h = ch;

            double aspect = (double)nativeSize.Height / (double)nativeSize.Width;

            //If specified, what percentage of the space do we use?
            if (o.PolyWidthInLogoPixels > 0) {
                w = cw * (double)nativeSize.Width / o.PolyWidthInLogoPixels;
                if (o.RespectOnlyMatchingBound) h = w * aspect;
            }

            if (o.PolyHeightInLogoPixels > 0) {
                h = ch * (double)nativeSize.Height / o.PolyHeightInLogoPixels;
                if (o.RespectOnlyMatchingBound && o.PolyWidthInLogoPixels <= 0) w = h / aspect;
            }

            //Shrink to keep aspect ratio
            if (w / h > 1 / aspect) {
                w = h / aspect;
            } else {
                h = w * aspect;
            }
            //Let's define our width/height offsets
            double ox = 0; double oy = 0; ;

            //Apply alignment to ox, oy
            if (o.Align == ContentAlignment.BottomLeft || o.Align == ContentAlignment.MiddleLeft || o.Align == ContentAlignment.TopLeft)
                ox = 0;
            if (o.Align == ContentAlignment.BottomCenter || o.Align == ContentAlignment.MiddleCenter || o.Align == ContentAlignment.TopCenter)
                ox = (cw - w) / 2;
            if (o.Align == ContentAlignment.BottomRight || o.Align == ContentAlignment.MiddleRight || o.Align == ContentAlignment.TopRight)
                ox = cw - w;
            if (o.Align == ContentAlignment.TopLeft || o.Align == ContentAlignment.TopCenter || o.Align == ContentAlignment.TopRight)
                oy = 0;
            if (o.Align == ContentAlignment.MiddleLeft || o.Align == ContentAlignment.MiddleCenter || o.Align == ContentAlignment.MiddleRight)
                oy = (ch - h) / 2;
            if (o.Align == ContentAlignment.BottomLeft || o.Align == ContentAlignment.BottomCenter || o.Align == ContentAlignment.BottomRight)
                oy = ch - h;

            //Now, we need to rotate everything to match the rotation of the original parallelogram
            double angle = Math.Atan2(o.Poly[1].Y - o.Poly[0].Y, o.Poly[1].X - o.Poly[0].X);

            PointF[] t = new PointF[4];
            t[0] = CreateVector(CreateVector(o.Poly[0], angle, ox), angle + Math.PI / 2, oy);
            t[1] = CreateVector(t[0], angle, w);
            t[2] = CreateVector(t[1], angle + Math.PI / 2, h);
            t[3] = CreateVector(t[0], angle + Math.PI / 2, h);

            //Translate the points if a ImageState instance was specified
            if (translateToFinalCoordinateSpace != null) return this.TranslatePoints(t, translateToFinalCoordinateSpace);
            return t;
        }
开发者ID:eakova,项目名称:resizer,代码行数:58,代码来源:LayoutEngine.cs


示例7: PostCreateImageAttributes

        protected override RequestedAction PostCreateImageAttributes(ImageState s)
        {
            if (s.copyAttibutes == null) return RequestedAction.None;

            if (!s.settings.WasOneSpecified(GetSupportedQuerystringKeys().ToArray())) return RequestedAction.None;

            s.copyAttibutes.SetColorMatrix(new ColorMatrix(Grayscale()));
            return RequestedAction.None;
        }
开发者ID:ThinkPublishing,项目名称:Summit.Core,代码行数:9,代码来源:GrayscaleFilter.cs


示例8: PostLayoutImage

 protected override RequestedAction PostLayoutImage(ImageState s)
 {
     //Now we offset copyRect so it works properly.
     if (s.Data.ContainsKey(RectDataKey)){
         Rectangle box = (Rectangle)s.Data[RectDataKey];
         s.copyRect = new RectangleF(s.copyRect.X + box.X, s.copyRect.Y + box.Y,s.copyRect.Width,s.copyRect.Height);
     }
     return RequestedAction.None;
 }
开发者ID:eakova,项目名称:resizer,代码行数:9,代码来源:WhitespaceTrimmerPlugin.cs


示例9: buildFiBitmap

        /// <summary>
        /// Builds an FIBitmap from the stream and job.Settings 
        /// </summary>
        /// <param name="s"></param>
        /// <param name="job"></param>
        /// <returns></returns>
        protected FIBITMAP buildFiBitmap(ref FIBITMAP original, ImageJob job, bool supportsTransparency, bool mayUnloadOriginal)
        {
            ResizeSettings settings = job.Settings;
            if (original.IsNull) return FIBITMAP.Zero;
            FIBITMAP final = FIBITMAP.Zero;

            //Find the image size
            Size orig = new Size((int)FreeImage.GetWidth(original), (int)FreeImage.GetHeight(original));

            //Calculate the new size of the image and the canvas.
            ImageState state = new ImageState(settings, orig, true);
            c.CurrentImageBuilder.Process(state);
            RectangleF imageDest = PolygonMath.GetBoundingBox(state.layout["image"]);

            if (imageDest.Width != orig.Width || imageDest.Height != orig.Height) {
                //Rescale
                bool temp;
                final = FreeImage.Rescale(original, (int)imageDest.Width, (int)imageDest.Height, FreeImageScalingPlugin.ParseResizeAlgorithm(settings["fi.scale"], FREE_IMAGE_FILTER.FILTER_BOX, out temp));
                if (mayUnloadOriginal) FreeImage.UnloadEx(ref original);
                if (final.IsNull) return FIBITMAP.Zero;
            } else {
                final = original;
            }

            RGBQUAD bgcolor = default(RGBQUAD);
            bgcolor.Color = settings.BackgroundColor;
            if (settings.BackgroundColor == Color.Transparent && !supportsTransparency)
                bgcolor.Color = Color.White;

            //If we need to leave padding, do so.
            BoxPadding outsideImage = new BoxPadding(imageDest.Left, imageDest.Top, state.destSize.Width - imageDest.Right, state.destSize.Height - imageDest.Bottom);

            if (outsideImage.All != 0) {
                var old = final;
                //Extend canvas
                final = FreeImage.EnlargeCanvas<RGBQUAD>(old,
                            (int)outsideImage.Left, (int)outsideImage.Top, (int)outsideImage.Right, (int)outsideImage.Bottom,
                            bgcolor.Color != Color.Transparent ? new Nullable<RGBQUAD>(bgcolor) : null,
                            FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA);
                if (old == original) {
                    if (mayUnloadOriginal) {
                        FreeImage.UnloadEx(ref original);
                        old = original;
                    }
                } else {
                    FreeImage.UnloadEx(ref old); //'old' has the original value of 'final', which we allocated.
                }
                if (final.IsNull) return FIBITMAP.Zero;
            }

            return final;
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:58,代码来源:FreeImageBuilder.cs


示例10: RenderImage

        protected override RequestedAction RenderImage(ImageState s)
        {
            //Skip this when we are doing simulations
            if (s.destGraphics == null) return RequestedAction.None;

            //If there's pre-rendering involved this optimization is utterly pointless.
            if (s.preRenderBitmap != null) return RequestedAction.None;

            //Find out what the speed setting is.
            int speed = 0;
            if (string.IsNullOrEmpty(s.settings["speed"]) || !int.TryParse(s.settings["speed"], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out speed)) speed = 0;

            if (speed < 1) return RequestedAction.None;

            s.destGraphics.CompositingMode = CompositingMode.SourceCopy;
            s.destGraphics.CompositingQuality = CompositingQuality.HighSpeed;
            if (speed == 1)
                s.destGraphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
            else
                s.destGraphics.InterpolationMode = InterpolationMode.Bilinear;

            s.destGraphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
            s.destGraphics.SmoothingMode = SmoothingMode.HighSpeed;

            s.copyAttibutes.SetWrapMode(WrapMode.TileFlipXY);

            if (speed < 3) {
                s.destGraphics.DrawImage(s.sourceBitmap, PolygonMath.getParallelogram(s.layout["image"]), s.copyRect, GraphicsUnit.Pixel, s.copyAttibutes);

            } else if (speed < 4) {
                Rectangle midsize = PolygonMath.ToRectangle(PolygonMath.GetBoundingBox(s.layout["image"]));

                using (Image thumb = s.sourceBitmap.GetThumbnailImage(midsize.Width, midsize.Height, delegate() { return false; }, IntPtr.Zero)) {
                    double xfactor = (double)thumb.Width / (double)s.sourceBitmap.Width;
                    double yfactor = (double)thumb.Height / (double)s.sourceBitmap.Height;
                    RectangleF copyPart = new RectangleF((float)(s.copyRect.Left * xfactor),
                                                        (float)(s.copyRect.Top * yfactor),
                                                        (float)(s.copyRect.Width * xfactor),
                                                        (float)(s.copyRect.Height * yfactor));
                    if (Math.Floor(copyPart.Height) == thumb.Height || Math.Ceiling(copyPart.Height) == thumb.Height) copyPart.Height = thumb.Height;
                    if (Math.Floor(copyPart.Width) == thumb.Width || Math.Ceiling(copyPart.Width) == thumb.Width) copyPart.Width = thumb.Width;
                    s.destGraphics.DrawImage(thumb, PolygonMath.getParallelogram(s.layout["image"]), copyPart, GraphicsUnit.Pixel, s.copyAttibutes);
                }
            } else {
                RectangleF box = PolygonMath.GetBoundingBox(PolygonMath.getParallelogram(s.layout["image"]));
                s.destGraphics.CompositingMode = CompositingMode.SourceCopy;
                s.destGraphics.DrawImage(s.sourceBitmap, box.Left, box.Top, box.Width, box.Height);
            }

            return RequestedAction.Cancel;
        }
开发者ID:eakova,项目名称:resizer,代码行数:51,代码来源:SpeedOrQuality.cs


示例11: LayoutImage

        protected override RequestedAction LayoutImage(ImageState s)
        {
            //Only activated if both width and height are specified, and mode=crop.
            if (s.settings.Mode != FitMode.Crop || s.settings.Width < 0 || s.settings.Height < 0) return RequestedAction.None;

            //Calculate bounding box for all coordinates specified.
            double[] focus = NameValueCollectionExtensions.GetList<double>(s.settings, "c.focus", null, 2, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72);
            if (focus == null) return RequestedAction.None;
            RectangleF box = PolygonMath.GetBoundingBox(focus);

            var bounds = new RectangleF(new PointF(0,0),s.originalSize);
            //Clip box to original image bounds
            box = PolygonMath.ClipRectangle(box, bounds);

            var targetSize = new SizeF(s.settings.Width,s.settings.Height);

            SizeF copySize;

            //Now, we can either crop as closely as possible or as loosely as possible.
            if (NameValueCollectionExtensions.Get<bool>(s.settings, "c.zoom", false) && box.Width > 0 && box.Height > 0) {
                //Crop close
                copySize = PolygonMath.ScaleOutside(box.Size, targetSize);
            } else {
                //Crop minimally
                copySize = PolygonMath.ScaleInside(targetSize, bounds.Size);
                //Ensure it's outside the box
                if (!PolygonMath.FitsInside(box.Size,copySize)) copySize = PolygonMath.ScaleOutside(box.Size, copySize);

            }
            //Clip to bounds.
            box = PolygonMath.ClipRectangle(PolygonMath.ExpandTo(box, copySize), bounds);

            s.copyRect = box;

            ///What is the vertical and horizontal aspect ratio different in result pixels?
            var padding = PolygonMath.ScaleInside(box.Size, targetSize);
            padding = new SizeF(targetSize.Width - padding.Width, targetSize.Height - padding.Height);

            //So, if we haven't met the aspect ratio yet, what mode will we pass on?
            var finalmode = NameValueCollectionExtensions.Get<FitMode>(s.settings, "c.finalmode", FitMode.Pad);

            //Crop off 1 or 2 pixels instead of padding without worrying too much
            if (finalmode == FitMode.Pad && padding.Width + padding.Height < 3) finalmode = FitMode.Crop;

            s.settings.Mode = finalmode;

            return RequestedAction.None;
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:48,代码来源:CropAroundPlugin.cs


示例12: PostRenderImage

        protected override RequestedAction PostRenderImage(ImageState s)
        {
            if (s.destBitmap == null) 
                return RequestedAction.None;
            if (!s.settings.WasOneSpecified(GetSupportedQuerystringKeys().ToArray()))
                return RequestedAction.None;;
            int blurSize; 
            if (!int.TryParse(s.settings["ipt.blur"], out blurSize))
            {
                return RequestedAction.None;
            }

            new GaussianBlur(1.4, blurSize).ApplyInPlace(s.destBitmap);

            return RequestedAction.None;
        }
开发者ID:CEBD,项目名称:MerrickHomeConstruction,代码行数:16,代码来源:BlurFilter.cs


示例13: RenderOverlays

        protected override RequestedAction RenderOverlays(ImageState s)
        {
            // Get 'sample' from the querystring
            string sample = s.settings["sample"];

            //Don't try to draw the string if it is empty, or if this is a 'simulation' render
            if (string.IsNullOrEmpty(sample) || s.destGraphics == null) return RequestedAction.None;

            //Let's use Arial, and make sure the text fits inside the bitmap width.
            System.Drawing.Font font = new System.Drawing.Font("Arial",
                (float)(s.destBitmap.Width / (sample.Length * 1.5f)), System.Drawing.GraphicsUnit.Pixel);

            //Draw the text at the top left corner of the resulting image.
            s.destGraphics.DrawString(sample, font, System.Drawing.Brushes.Black, 0, 0);

            return RequestedAction.None;
        }
开发者ID:eakova,项目名称:resizer,代码行数:17,代码来源:SamplePlugin.cs


示例14: PostLayoutImage

        protected override RequestedAction PostLayoutImage(ImageState s)
        {
            base.PostLayoutImage(s);

            if (!limits.HasImageSize) return RequestedAction.None;//Skip this unless we have image size limits

            SizeF box = s.layout.GetBoundingBox().Size;

            double wFactor = box.Width / limits.ImageSize.Width;
            double hFactor = box.Height / limits.ImageSize.Height;

            double scaleFactor = wFactor > hFactor ? wFactor : hFactor;
            if (scaleFactor > 1) {
                //The bounding box exceeds the ImageSize. Scale down until it fits.
                s.layout.Scale(1 / scaleFactor, new PointF(0, 0));
            }

            return RequestedAction.None;
        }
开发者ID:eakova,项目名称:resizer,代码行数:19,代码来源:SizeLimiting.cs


示例15: LayoutEffects

        protected override RequestedAction LayoutEffects(ImageState s)
        {
            float shadowWidth = s.settings.Get<float>("shadowWidth", 0);
            if (shadowWidth != 0) {

                var offset = NameValueCollectionExtensions.GetList<float>(s.settings, "shadowOffset", 0, 2);
                PointF shadowOffset =  offset == null ? new PointF(0,0) : new PointF(offset[0], offset[1]);

                //Clone last ring, then offset it - provides the inner bounds of the shadow later
                s.layout.AddInvisiblePolygon("shadowInner", PolygonMath.MovePoly(s.layout.LastRing.points, shadowOffset));

                //Determine the outer bound of the shadow
                s.layout.AddRing("shadow", PolygonMath.InflatePoly(s.layout.LastRing.points, new float[]{
                    Math.Max(0, shadowWidth - shadowOffset.Y),
                    Math.Max(0, shadowWidth + shadowOffset.X),
                    Math.Max(0, shadowWidth + shadowOffset.Y),
                    Math.Max(0, shadowWidth - shadowOffset.X)
                }));
            }
            return RequestedAction.None;
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:21,代码来源:DropShadow.cs


示例16: PostRenderImage

        protected override RequestedAction PostRenderImage(ImageState s)
        {
            if (s.destBitmap == null) return RequestedAction.None;
            string str = null;
            int i = 0;

             if ("true".Equals(s.settings["r.autoeyes"], StringComparison.OrdinalIgnoreCase)) {
                 List<ObjRect> eyes;
                 using (var ed = new EyeDetection()) eyes = ed.DetectFeatures(s.sourceBitmap);

                 List<PointF> points = new List<PointF>();
                 foreach(ObjRect r in eyes) { points.Add(new PointF(r.X,r.Y)); points.Add(new PointF(r.X2,r.Y2));}
                 PointF[] newPoints = c.CurrentImageBuilder.TranslatePoints(points.ToArray(),s.originalSize,new ResizeSettings(s.settings));
                 using (Graphics g = Graphics.FromImage(s.destBitmap)){
                     for(i =0; i < newPoints.Length -1; i+=2){
                         float x1 = newPoints[i].X;
                         float y1 = newPoints[i].Y;
                         float x2 = newPoints[i + 1].X;
                         float y2 = newPoints[i + 1].Y;
                         float t;
                         if (x1 > x2){ t = x2; x2  =x1; x1 = t;}
                         if (y1 > y2){ t = y1; y1 = y2; y2 = t;}

                         g.DrawRectangle(eyes[i /2].Feature == FeatureType.Eye ? Pens.Green : Pens.Gray,new Rectangle((int)x1,(int)y1,(int)(x2-x1),(int)(y2-y1)));
                     }
                 }
             }

            str = s.settings["r.filter"]; //radius
            if (!string.IsNullOrEmpty(str) && int.TryParse(str, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i)) {
                using (s.destBitmap) {
                    s.destBitmap = new RedEyeFilter((short)i).Apply(s.destBitmap);
                }
                //Note to future self: sobel/canny/eye kernel convolutions were not helpful; they were dead ends.
             }
            return RequestedAction.None;
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:37,代码来源:RedEyePlugin.cs


示例17: PreRenderImage

        /// <summary>
        /// Supporting rounded corners.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        protected override RequestedAction PreRenderImage(ImageState s)
        {
            if (s.sourceBitmap == null) return RequestedAction.None;
            double[] vals = NameValueCollectionExtensions.GetList<double>(s.settings, "s.roundcorners",0,1,4);
            if (vals == null) return RequestedAction.None;

            if (vals.Length == 1)  vals = new double[]{vals[0],vals[0],vals[0],vals[0]};

            bool hasValue = false;
            foreach (double d in vals) if (d > 0) hasValue = true;
            if (!hasValue) return RequestedAction.None;

            Bitmap cropped = null;
            try{
                //Make sure cropping is applied, and use existing prerendered bitmap if present.
                s.ApplyCropping();

                cropped = s.preRenderBitmap ?? s.sourceBitmap;

                s.preRenderBitmap = new Bitmap(cropped.Width,cropped.Height, PixelFormat.Format32bppArgb);

                int[] radius = new int[4];
                //Radius percentages are 0-100, a percentage of the smaller of the width and height.
                for (int i = 0; i < vals.Length; i++) radius[i] = (int)Math.Round(Math.Max(0,Math.Min(99.999,vals[i])) * ((double)Math.Min(s.preRenderBitmap.Width,s.preRenderBitmap.Height) / 100));

                s.preRenderBitmap.MakeTransparent();
                using (Graphics g = Graphics.FromImage(s.preRenderBitmap)) {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.CompositingMode = CompositingMode.SourceOver;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    using (TextureBrush tb = new TextureBrush(cropped))
                    using (GraphicsPath gp = new GraphicsPath(FillMode.Winding)) {
                        Rectangle bounds = new Rectangle(0, 0, s.preRenderBitmap.Width, s.preRenderBitmap.Height);
                        int[] angles = new int[]{180,270,0,90};
                        int[] xs = new int[]{bounds.X,bounds.Right - radius[1], bounds.Right - radius[2], bounds.X};
                        int[] ys = new int[]{bounds.Y,bounds.Y,bounds.Bottom - radius[2], bounds.Bottom - radius[3]};
                        for (int i =0; i < 4; i++){
                            if (radius[i] > 0){
                                gp.AddArc(xs[i],ys[i],radius[i],radius[i],angles[i],90);
                            }else{
                                gp.AddLine(xs[i],ys[i],xs[i],ys[i]);
                            }
                        }
                        g.FillPath(tb, gp);

                    }
                }
            }finally{
                if (cropped != null & cropped != s.sourceBitmap) cropped.Dispose();
            }
            return RequestedAction.None;
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:58,代码来源:SimpleFilters.cs


示例18: PrepareDestinationBitmap

        /// <summary>
        /// Creates a bitmap of s.destSize dimensions, intializes a graphics object for it, and configures all the default settings.
        /// </summary>
        /// <param name="s"></param>
        protected override RequestedAction PrepareDestinationBitmap(ImageState s)
        {
            if (base.PrepareDestinationBitmap(s) == RequestedAction.Cancel) return RequestedAction.Cancel;

             if (s.sourceBitmap == null) return RequestedAction.None;

            //Create new bitmap using calculated size.
            s.destBitmap = new Bitmap(s.destSize.Width,s.destSize.Height, PixelFormat.Format32bppArgb);

            //Create graphics handle
            Graphics g = s.destGraphics = Graphics.FromImage(s.destBitmap);

            //High quality everthing
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.CompositingMode = CompositingMode.SourceOver;
            return RequestedAction.None;
        }
开发者ID:eakova,项目名称:resizer,代码行数:24,代码来源:ImageBuilder.cs


示例19: LayoutRound

 protected override RequestedAction LayoutRound(ImageState s)
 {
     if (base.LayoutRound(s) == RequestedAction.Cancel) return RequestedAction.Cancel; //Call extensions
     //Todo, round points here.
     //s.layout.Round();
     return RequestedAction.None;
 }
开发者ID:eakova,项目名称:resizer,代码行数:7,代码来源:ImageBuilder.cs


示例20: LayoutRotate

 protected override RequestedAction LayoutRotate(ImageState s)
 {
     if (base.LayoutRotate(s) == RequestedAction.Cancel) return RequestedAction.Cancel; //Call extensions
     //Now, rotate all rings.
     s.layout.Rotate(s.settings.Rotate, new PointF(0, 0));
     return RequestedAction.None;
 }
开发者ID:eakova,项目名称:resizer,代码行数:7,代码来源:ImageBuilder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Impl.ImgurClient类代码示例发布时间:2022-05-26
下一篇:
C# ImageMagick.MagickImageCollection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap