private void PaintFigure(ShapeFigure shape) { InterpolationMode oldmode = Graphics.InterpolationMode; Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; using (Image smallImg = CreateShapeImage(shape, shape.VirtualBounds, shape.BorderWidth * shape.Zoom)) using (Image virtualImg = ImageHelper.ReSizeImage(smallImg, shape.VirtualBounds.Width, shape.VirtualBounds.Height)) using (ImageAttributes imgAttri = new ImageAttributes()) { imgAttri.SetColorKey((Color)shape.TranColor, (Color)shape.TranColor); Graphics.DrawImage(virtualImg, shape.VirtualBounds, 0, 0, shape.VirtualBounds.Width, shape.VirtualBounds.Height, GraphicsUnit.Pixel, imgAttri); Graphics.InterpolationMode = oldmode; } }
private static Image CreateShapeImage(ShapeFigure shape, Rectangle innbounds, int borderwidth) { innbounds.Width = innbounds.Width < shape.Zoom ? shape.Zoom : innbounds.Width; innbounds.Height = innbounds.Height < shape.Zoom ? shape.Zoom : innbounds.Height; Rectangle adjRect = new Rectangle(0, 0, innbounds.Width, innbounds.Height); int w = adjRect.Width / shape.Zoom < 1 ? 1 : adjRect.Width / shape.Zoom; int h = adjRect.Height / shape.Zoom < 1 ? 1 : adjRect.Height / shape.Zoom; using (Image img = new Bitmap(innbounds.Width + 1, innbounds.Height + 1)) { using (Graphics g = Graphics.FromImage(img)) PaintFigure(g, adjRect, shape, borderwidth); return(ImageHelper.ReSizeImage(img, w, h)); } }
private static void PaintFigure(Graphics g, RectangleF innbounds, ShapeFigure shape, int borderwidth) { using (GraphicsPath gp = new GraphicsPath()) { switch (shape.Type) { case ShapeType.Rectangle: gp.AddRectangle(ShapePaintHelper.GetNormalizedRectangle(Rectangle.Round(innbounds))); break; case ShapeType.Ellipse: gp.AddEllipse(ShapePaintHelper.GetNormalizedRectangle(Rectangle.Round(innbounds))); break; case ShapeType.UpArrow: gp.AddPolygon(Rect2PointFArray(Rectangle.Round(innbounds), ArrowDirection.Up)); break; case ShapeType.DownArrow: gp.AddPolygon(Rect2PointFArray(Rectangle.Round(innbounds), ArrowDirection.Down)); break; case ShapeType.RightArrow: gp.AddPolygon(Rect2PointFArray(Rectangle.Round(innbounds), ArrowDirection.Right)); break; case ShapeType.LeftArrow: gp.AddPolygon(Rect2PointFArray(Rectangle.Round(innbounds), ArrowDirection.Left)); break; default: return; } if (shape.Filled) { g.FillPath(ResourceCache.DefaultCache.GetSolidBrush(shape.FillColor), gp); } using (Pen pen = ResourceCache.DefaultCache.GetPen(shape.BorderColor, borderwidth, PenAlignment.Inset, shape.LineDashStyle)) g.DrawPath(pen, gp); } }