public override System.Drawing.Brush CreateGDIBrush(RectangleF rc, float dx, float dy) { RectangleF rct = new RectangleF(0, 0, _image.Width, _image.Height); System.Drawing.TextureBrush brush = new System.Drawing.TextureBrush(_image, _wrapMode, rct); brush.TranslateTransform(dx, dy); brush.ScaleTransform(24.0f / 80, 24.0f / 80, MatrixOrder.Append); return(brush); }
/// <summary> /// 转圆形图片 /// </summary> /// <param name="img"></param> /// <param name="rec"></param> /// <param name="size"></param> /// <returns></returns> private System.Drawing.Image CutEllipse(System.Drawing.Image img, Rectangle rec, Size size) { Bitmap bitmap = new Bitmap(size.Width, size.Height); using (Graphics g = Graphics.FromImage(bitmap)) { using (TextureBrush br = new System.Drawing.TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, rec)) { br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.FillEllipse(br, new Rectangle(Point.Empty, size)); } } return(bitmap); }
void CreatePatternBrush(float pixelSize) { // Determine adjusted pixel size of the brush to create. const float MAX_PATTERN_SIZE = 80; const float MIN_PATTERN_SIZE = 10; if (pixelSize < patternWidth / MAX_PATTERN_SIZE) pixelSize = patternWidth / MAX_PATTERN_SIZE; if (pixelSize < patternHeight / MAX_PATTERN_SIZE) pixelSize = patternHeight / MAX_PATTERN_SIZE; if (pixelSize > patternWidth / MIN_PATTERN_SIZE) pixelSize = patternWidth / MIN_PATTERN_SIZE; if (pixelSize > patternHeight / MIN_PATTERN_SIZE) pixelSize = patternHeight / MIN_PATTERN_SIZE; if (patternBrushes != null && Math.Abs(pixelSize - pixelSizeCached) / pixelSize < 0.01) return; // the pattern brush is already OK size. // Get size of bitmap to create with the image of the pattern. float width = (float) Math.Round(patternWidth / pixelSize); float height = (float) Math.Round(patternHeight / pixelSize); // Create dictionary to hold brushes for each color. patternBrushes = new Dictionary<SymColor, Brush>(2); pixelSizeCached = pixelSize; RenderOptions renderOpts = new RenderOptions(); renderOpts.minResolution = pixelSize; renderOpts.usePatternBitmaps = false; foreach (SymColor color in map.colors) { if (!patternGlyph.HasColor(color)) continue; // Create a new bitmap and fill it transparent. Bitmap bitmap = new Bitmap((int) width, (int) (offsetRows ? height * 2 : height)); Graphics g = Graphics.FromImage(bitmap); g.CompositingMode = CompositingMode.SourceCopy; g.SmoothingMode = SmoothingMode.HighQuality; g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, bitmap.Width, bitmap.Height); // Set the center of the bitmap to 0,0, and scale to mm (each pixel is 0.01 mm). g.TranslateTransform(width / 2.0F, height / 2.0F); g.ScaleTransform(width / patternWidth, height / patternHeight); // Draw the pattern into the bitmap. GraphicsTarget grTarget = new GraphicsTarget(g); patternGlyph.Draw(grTarget, new PointF(0F, 0F), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts); if (offsetRows) { patternGlyph.Draw(grTarget, new PointF(patternWidth / 2, patternHeight), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts); patternGlyph.Draw(grTarget, new PointF(-patternWidth / 2, patternHeight), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts); } // Create a TextureBrush on the bitmap. TextureBrush brush = new TextureBrush(bitmap); // Scale and the texture brush. brush.RotateTransform(patternAngle); brush.ScaleTransform(patternWidth / width, patternHeight / height); brush.TranslateTransform(-width / 2.0F, -height / 2.0F); // Dispose of the graphics. g.Dispose(); // Add it to the collection of brushes. patternBrushes.Add(color, brush); } }
public override void setPaint(java.awt.Paint paint) { if (paint is java.awt.Color) { setColor((java.awt.Color)paint); return; } if (paint == null || this.javaPaint == paint) { return; } this.javaPaint = paint; if (paint is java.awt.GradientPaint) { java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint; LinearGradientBrush linear; if (gradient.isCyclic()) { linear = new LinearGradientBrush( J2C.ConvertPoint(gradient.getPoint1()), J2C.ConvertPoint(gradient.getPoint2()), composite.GetColor(gradient.getColor1()), composite.GetColor(gradient.getColor2())); } else { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 4 color values // a exact solution will calculate the size of the Graphics with the current transform Color color1 = composite.GetColor(gradient.getColor1()); Color color2 = composite.GetColor(gradient.getColor2()); float x1 = (float)gradient.getPoint1().getX(); float x2 = (float)gradient.getPoint2().getX(); float y1 = (float)gradient.getPoint1().getY(); float y2 = (float)gradient.getPoint2().getY(); float diffX = x2 - x1; float diffY = y2 - y1; const float z = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider. linear = new LinearGradientBrush( new PointF(x1 - z * diffX, y1 - z * diffY), new PointF(x2 + z * diffX, y2 + z * diffY), color1, color1); ColorBlend colorBlend = new ColorBlend(4); Color[] colors = colorBlend.Colors; colors[0] = colors[1] = color1; colors[2] = colors[3] = color2; float[] positions = colorBlend.Positions; positions[1] = z / (2 * z + 1); positions[2] = (z + 1) / (2 * z + 1); positions[3] = 1.0f; linear.InterpolationColors = colorBlend; } linear.WrapMode = WrapMode.TileFlipXY; brush = linear; pen.Brush = brush; return; } if (paint is java.awt.TexturePaint) { java.awt.TexturePaint texture = (java.awt.TexturePaint)paint; Bitmap txtr = J2C.ConvertImage(texture.getImage()); java.awt.geom.Rectangle2D anchor = texture.getAnchorRect(); TextureBrush txtBrush; brush = txtBrush = new TextureBrush(txtr, new Rectangle(0, 0, txtr.Width, txtr.Height), composite.GetImageAttributes()); txtBrush.TranslateTransform((float)anchor.getX(), (float)anchor.getY()); txtBrush.ScaleTransform((float)anchor.getWidth() / txtr.Width, (float)anchor.getHeight() / txtr.Height); txtBrush.WrapMode = WrapMode.Tile; pen.Brush = brush; return; } if (paint is java.awt.LinearGradientPaint) { java.awt.LinearGradientPaint gradient = (java.awt.LinearGradientPaint)paint; PointF start = J2C.ConvertPoint(gradient.getStartPoint()); PointF end = J2C.ConvertPoint(gradient.getEndPoint()); java.awt.Color[] javaColors = gradient.getColors(); ColorBlend colorBlend; Color[] colors; bool noCycle = gradient.getCycleMethod() == java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE; if (noCycle) { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 2 additional color values //an exact solution will calculate the size of the Graphics with the current transform float diffX = end.X - start.X; float diffY = end.Y - start.Y; SizeF size = GetSize(); //HACK zoom factor, with a larger factor .NET will make the gradient wider. float z = Math.Min(10, Math.Max(size.Width / diffX, size.Height / diffY)); start.X -= z * diffX; start.Y -= z * diffY; end.X += z * diffX; end.Y += z * diffY; colorBlend = new ColorBlend(javaColors.Length + 2); colors = colorBlend.Colors; float[] fractions = gradient.getFractions(); float[] positions = colorBlend.Positions; for (int i = 0; i < javaColors.Length; i++) { colors[i + 1] = composite.GetColor(javaColors[i]); positions[i + 1] = (z + fractions[i]) / (2 * z + 1); } colors[0] = colors[1]; colors[colors.Length - 1] = colors[colors.Length - 2]; positions[positions.Length - 1] = 1.0f; } else { colorBlend = new ColorBlend(javaColors.Length); colors = colorBlend.Colors; colorBlend.Positions = gradient.getFractions(); for (int i = 0; i < javaColors.Length; i++) { colors[i] = composite.GetColor(javaColors[i]); } } LinearGradientBrush linear = new LinearGradientBrush(start, end, colors[0], colors[colors.Length - 1]); linear.InterpolationColors = colorBlend; switch (gradient.getCycleMethod().ordinal()) { case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE: case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT: linear.WrapMode = WrapMode.TileFlipXY; break; case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REPEAT: linear.WrapMode = WrapMode.Tile; break; } brush = linear; pen.Brush = brush; return; } if (paint is java.awt.RadialGradientPaint ) { java.awt.RadialGradientPaint gradient = (java.awt.RadialGradientPaint)paint; GraphicsPath path = new GraphicsPath(); SizeF size = GetSize(); PointF center = J2C.ConvertPoint(gradient.getCenterPoint()); float radius = gradient.getRadius(); int factor = (int)Math.Ceiling(Math.Max(size.Width, size.Height) / radius); float diameter = radius * factor; path.AddEllipse(center.X - diameter, center.Y - diameter, diameter * 2, diameter * 2); java.awt.Color[] javaColors = gradient.getColors(); float[] fractions = gradient.getFractions(); int length = javaColors.Length; ColorBlend colorBlend = new ColorBlend(length * factor); Color[] colors = colorBlend.Colors; float[] positions = colorBlend.Positions; for (int c = 0, j = length - 1; j >= 0; ) { positions[c] = (1 - fractions[j]) / factor; colors[c++] = composite.GetColor(javaColors[j--]); } java.awt.MultipleGradientPaint.CycleMethod.__Enum cycle = (java.awt.MultipleGradientPaint.CycleMethod.__Enum)gradient.getCycleMethod().ordinal(); for (int f = 1; f < factor; f++) { int off = f * length; for (int c = 0, j = length - 1; j >= 0; j--, c++) { switch (cycle) { case java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT: if (f % 2 == 0) { positions[off + c] = (f + 1 - fractions[j]) / factor; colors[off + c] = colors[c]; } else { positions[off + c] = (f + fractions[c]) / factor; colors[off + c] = colors[j]; } break; case java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE: positions[off + c] = (f + 1 - fractions[j]) / factor; break; default: //CycleMethod.REPEAT positions[off + c] = (f + 1 - fractions[j]) / factor; colors[off + c] = colors[c]; break; } } } if (cycle == java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE && factor > 1) { Array.Copy(colors, 0, colors, colors.Length - length, length); Color color = colors[length - 1]; for (int i = colors.Length - length - 1; i >= 0; i--) { colors[i] = color; } } PathGradientBrush pathBrush = new PathGradientBrush(path); pathBrush.CenterPoint = center; pathBrush.InterpolationColors = colorBlend; brush = pathBrush; pen.Brush = brush; return; } //generic paint to brush conversion for custom paints //the tranform of the graphics should not change between the creation and it usage using (Matrix transform = g.Transform) { SizeF size = GetSize(); int width = (int)size.Width; int height = (int)size.Height; java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, width, height); java.awt.PaintContext context = paint.createContext(ColorModel.getRGBdefault(), bounds, bounds, C2J.ConvertMatrix(transform), getRenderingHints()); WritableRaster raster = (WritableRaster)context.getRaster(0, 0, width, height); BufferedImage txtrImage = new BufferedImage(context.getColorModel(), raster, true, null); Bitmap txtr = J2C.ConvertImage(txtrImage); TextureBrush txtBrush; brush = txtBrush = new TextureBrush(txtr, new Rectangle(0, 0, width, height), composite.GetImageAttributes()); transform.Invert(); txtBrush.Transform = transform; txtBrush.WrapMode = WrapMode.Tile; pen.Brush = brush; return; } }
private static Brush CreateImageBrush(Rectangle rect, Image image, PaletteImageStyle imageStyle) { // Create brush based on the provided image TextureBrush brush = new TextureBrush(image); // Create appropriate wrapping mode from image style switch (imageStyle) { case PaletteImageStyle.TopLeft: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left, rect.Top); break; case PaletteImageStyle.TopMiddle: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left + (rect.Width - image.Width) / 2, rect.Top); break; case PaletteImageStyle.TopRight: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Right - image.Width, rect.Top); break; case PaletteImageStyle.CenterLeft: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left, rect.Top + (rect.Height - image.Height) / 2); break; case PaletteImageStyle.CenterMiddle: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left + (rect.Width - image.Width) / 2, rect.Top + (rect.Height - image.Height) / 2); break; case PaletteImageStyle.CenterRight: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Right - image.Width, rect.Top + (rect.Height - image.Height) / 2); break; case PaletteImageStyle.BottomLeft: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left, rect.Bottom - image.Height); break; case PaletteImageStyle.BottomMiddle: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left + (rect.Width - image.Width) / 2, rect.Bottom - image.Height); break; case PaletteImageStyle.BottomRight: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Right - image.Width, rect.Bottom - image.Height); break; case PaletteImageStyle.Stretch: brush.WrapMode = WrapMode.Clamp; brush.TranslateTransform(rect.Left, rect.Top); brush.ScaleTransform((float)rect.Width / (float)image.Width, (float)rect.Height / (float)image.Height); break; case PaletteImageStyle.Tile: brush.WrapMode = WrapMode.Tile; brush.TranslateTransform(rect.Left, rect.Top); break; case PaletteImageStyle.TileFlipX: brush.WrapMode = WrapMode.TileFlipX; brush.TranslateTransform(rect.Left, rect.Top); break; case PaletteImageStyle.TileFlipY: brush.WrapMode = WrapMode.TileFlipY; brush.TranslateTransform(rect.Left, rect.Top); break; case PaletteImageStyle.TileFlipXY: brush.WrapMode = WrapMode.TileFlipXY; brush.TranslateTransform(rect.Left, rect.Top); break; default: // Should never happen! Debug.Assert(false); throw new ArgumentOutOfRangeException("imageStyle"); } return brush; }
/// <summary> /// Draws a graph of friends into a Bitmap /// </summary> /// <param name="graph">Friend connection graf</param> /// <param name="srcDir">Where to take user profile picture thumbnails from</param> /// <param name="settings">Settings - when left blank, default settings are used</param> /// <param name="worker">To report the progress</param> /// <returns>Bitmap with the graph</returns> private static Bitmap DrawGraph(FriendGraph graph, string imageDir, BackgroundWorker worker = null) { Bitmap bmp = new Bitmap(GraphSettings.ImageWidth, GraphSettings.ImageHeight); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // if we have the autosize option on, we find the maximum number of friends int maxFriends = 0; // we draw lines connecting friends int i = 0; List<Friend> done = new List<Friend>(); // so we dont draw lines both ways foreach(KeyValuePair<Friend, List<Friend>> pair in graph) { if(worker != null && worker.CancellationPending) throw new InterruptedException(); Pen pen = new Pen(Color.FromArgb(64, 0, 0, 0), 1); foreach(Friend f in pair.Value) { if(!done.Contains(f)) g.DrawLine(pen, pair.Key.coordinates, f.coordinates); } if(pair.Value.Count > maxFriends) maxFriends = pair.Value.Count; pen.Dispose(); done.Add(pair.Key); if(worker != null) worker.ReportProgress(Math.Min(99, ++i * 50 / graph.Count)); } int photoSize = GraphSettings.PhotoSize; // if we have the autosize option on, we would like bigger pictures be on top of smaller // we sort them by their friend count asc if(GraphSettings.AutoSize) { done.Sort((x, y) => { if(graph[x].Count < graph[y].Count) return -1; else if(graph[y].Count < graph[x].Count) return 1; return 0; }); } // we draw profile photos inside foreach(Friend f in done) { if(worker != null && worker.CancellationPending) throw new InterruptedException(); Image photo = Image.FromFile(imageDir + "/photos/" + f.id + ".jpg"); if(GraphSettings.AutoSize) { photoSize = (int) (15 + 35 * ((float) graph[f].Count / (float) maxFriends)); } if(GraphSettings.PhotoShape == Shape.Circle) { // we must crop circle out of the profile picture // we create brush TextureBrush brush = new TextureBrush(photo, WrapMode.Clamp); // resize the brush brush.ScaleTransform(((float) photoSize) / 50f, ((float) photoSize) / 50f, MatrixOrder.Append); // we reset the brush starting position brush.TranslateTransform(f.coordinates.X - photoSize / 2, f.coordinates.Y - photoSize / 2, MatrixOrder.Append); // and fill a circle with it g.FillEllipse(brush, f.coordinates.X - photoSize / 2, f.coordinates.Y - photoSize / 2, photoSize, photoSize); brush.Dispose(); } else { // square - just draw the image g.DrawImage(photo, f.coordinates.X - photoSize / 2, f.coordinates.Y - photoSize / 2, photoSize, photoSize); } photo.Dispose(); if(worker != null) worker.ReportProgress(Math.Min(99, ++i * 50 / graph.Count)); } g.Dispose(); return bmp; }
public override System.Drawing.Brush CreateGDIBrush(RectangleF rc, float dx, float dy) { RectangleF rct = new RectangleF(0, 0, _image.Width, _image.Height); System.Drawing.TextureBrush brush = new System.Drawing.TextureBrush(_image, _wrapMode, rct); brush.TranslateTransform(dx, dy); brush.ScaleTransform(24.0f/80, 24.0f/80, MatrixOrder.Append); return brush; }
public static d.Brush ToGdiPlus(this ImageBrush brush, Rect bounds) { var img = brush.ImageSource; var bt = new BrushTransform(brush, bounds); if (bt.DegenerateBrush != null) return bt.DegenerateBrush; var viewbox = brush.Viewbox; if (brush.ViewboxUnits == BrushMappingMode.RelativeToBoundingBox) viewbox.Scale(img.Width, img.Height); var viewport = brush.Viewport; if (brush.ViewportUnits == BrushMappingMode.RelativeToBoundingBox) viewport.Transform(bt.ToAbsolute); var ia = new di.ImageAttributes(); ia.SetColorMatrix(new di.ColorMatrix { Matrix33 = (float)brush.Opacity }); var b = new d.TextureBrush(img.ToGdiPlus(), viewbox.ToGdiPlus(), ia); b.WrapMode = brush.TileMode.ToGdiPlus(); b.TranslateTransform((float)viewport.X, (float)viewport.Y); b.ScaleTransform((float)(viewport.Width/viewbox.Width), (float)(viewport.Height/viewbox.Height)); b.MultiplyTransform(bt.ToBrush.ToGdiPlus(), d2.MatrixOrder.Append); return b; }
public void ScaleTransform_InvalidOrder () { TextureBrush t = new TextureBrush (image); t.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue); }
public void ScaleTransform_MaxMin () { TextureBrush t = new TextureBrush (image); t.ScaleTransform (Single.MaxValue, Single.MinValue); float[] elements = t.Transform.Elements; Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0"); Assert.AreEqual (0, elements[1], 0.1, "matrix.1"); Assert.AreEqual (0, elements[2], 0.1, "matrix.2"); Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3"); Assert.AreEqual (0, elements[4], 0.1, "matrix.4"); Assert.AreEqual (0, elements[5], 0.1, "matrix.5"); }
public void ScaleTransform () { TextureBrush t = new TextureBrush (image); t.ScaleTransform (2, 4); float[] elements = t.Transform.Elements; Assert.AreEqual (2, elements[0], 0.1, "matrix.0"); Assert.AreEqual (0, elements[1], 0.1, "matrix.1"); Assert.AreEqual (0, elements[2], 0.1, "matrix.2"); Assert.AreEqual (4, elements[3], 0.1, "matrix.3"); Assert.AreEqual (0, elements[4], 0.1, "matrix.4"); Assert.AreEqual (0, elements[5], 0.1, "matrix.5"); t.ScaleTransform (0.5f, 0.25f); Assert.IsTrue (t.Transform.IsIdentity, "Transform.IsIdentity"); }
public void Redraw() { //float xScl = 0, yScl = 0; this._drawing = true; try { // Use a bitmap object for drawing. This prevents the flicker. using (Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height)) { // Create a Graphics object to draw into the bitmap object. using (Graphics gBmp = Graphics.FromImage(bmp)) { if (_mSamp) { gBmp.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; gBmp.CompositingQuality = this._compQual; gBmp.InterpolationMode = this._intrpQual; gBmp.SmoothingMode = this._smthMode; } // Create a brush to use for drawing the control's background. Brush backBrush = null; Bitmap bgImg = null; { // Calculate the center of the control's client area. int xCen = this.ClientRectangle.Width / 2, yCen = this.ClientRectangle.Height / 2; // Draw the background, effectively erasing the control. // First, we need to clear the image to the proper // background color. gBmp.Clear(this.BackColor); // Then draw the background image, if there is one. if (this.BackgroundImage != null) { // If the control has a background image, we need to draw // that image instead of the background color. bgImg = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); using (Graphics gBg = Graphics.FromImage(bgImg)) { // Clear the bgImg with the backcolor. gBg.Clear(this.BackColor); // Get a texture brush to draw the control's // background image onto. using (TextureBrush tBrush = new TextureBrush(this.BackgroundImage)) { // Determine the image layout. switch (this.BackgroundImageLayout) { case ImageLayout.None: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; } break; case ImageLayout.Tile: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; } break; case ImageLayout.Zoom: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; Rectangle drawSize = RainstormStudios.Drawing.Imaging.ZoomImage(this.BackgroundImage, this.ClientRectangle); tBrush.TranslateTransform(drawSize.X, drawSize.Y); tBrush.ScaleTransform(((float)drawSize.Width) / ((float)this.BackgroundImage.Width), ((float)drawSize.Height) / ((float)this.BackgroundImage.Height)); //xScl = ((float)drawSize.Width) / ((float)this.BackgroundImage.Width); //yScl = ((float)drawSize.Height) / ((float)this.BackgroundImage.Height); } break; case ImageLayout.Stretch: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; tBrush.ScaleTransform(((float)this.ClientRectangle.Width) / ((float)this.BackgroundImage.Width), ((float)this.ClientRectangle.Height) / ((float)this.BackgroundImage.Height)); //xScl = ((float)this.ClientRectangle.Width) / ((float)this.BackgroundImage.Width); //yScl = ((float)this.ClientRectangle.Height) / ((float)this.BackgroundImage.Height); } break; case ImageLayout.Center: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; Point drawPoint = RainstormStudios.Drawing.Imaging.CenterImage(this.BackgroundImage, this.ClientRectangle); tBrush.TranslateTransform(drawPoint.X, drawPoint.Y); } break; } if (this._bgRot != 0) { tBrush.RotateTransform(this._bgRot); // Rotation is done at the top-left corner, so to // keep the image centered, we have to adjust // the translation transformation. // TODO:: Will determine how to do this later. } gBg.FillRectangle(tBrush, 0, 0, bgImg.Width, bgImg.Height); } } backBrush = new TextureBrush(bgImg); gBmp.FillRectangle(backBrush, this.ClientRectangle); } else // If there's no background image, then just set the // background brush to the background color. backBrush = new SolidBrush(this.BackColor); // Create a brush using the control's ForeColor and draw a // circle padded 5px from the control's client area on all sides. using (SolidBrush foreBrush = new SolidBrush(this.ForeColor)) gBmp.FillEllipse(foreBrush, this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); // If the designer specified a center hole "punch-out", // draw another circle with the background brush. if (_inrDiam > 0) { // Calculate the inner circle size/position. Point inrOrig = new Point((bmp.Width / 2) - _inrDiam, (bmp.Height / 2) - _inrDiam); Size inrSize = new Size(bmp.Width - (((bmp.Width / 2) - _inrDiam) * 2), bmp.Height - (((bmp.Height / 2) - _inrDiam) * 2)); Rectangle inrRect = new Rectangle(inrOrig, inrSize); // Draw the Ellipse. gBmp.FillEllipse(backBrush, inrRect); // Clear the size/position objects to release memory. inrRect = Rectangle.Empty; inrOrig = Point.Empty; inrSize = Size.Empty; } //if (_holeWidth > 0) // gBmp.FillEllipse(backBrush, (this.ClientRectangle.X / 2) - _holeWidth, (this.ClientRectangle.Y / 2) - _holeWidth, _holeWidth * 2, _holeWidth * 2); // Calculate the 'orbital' positions around the center of the control // that the lines will be drawn to. int[] t = new int[_lineCnt]; double[] a = new double[_lineCnt]; double[] xPos = new double[_lineCnt]; double[] yPos = new double[_lineCnt]; using (Pen penLine = new Pen(backBrush, _penWidth)) { for (int i = 0; i < _lineCnt; i++) { t[i] = _t + (i * ((base_prec * _prec) / _lineCnt)); if (t[i] > (base_prec * _prec)) t[i] = t[i] - (base_prec * _prec); a[i] = System.Math.PI * t[i] / ((base_prec * _prec) / 2); if (_funk) { if (i % 2 > 0) { xPos[i] = xCen + (this.ClientRectangle.Width / 2) * System.Math.Sin(a[i]); yPos[i] = (yCen * (this.ClientRectangle.Height / 2) * System.Math.Cos(a[i])) / 2; } else { xPos[i] = (xCen * (this.ClientRectangle.Width / 2) * System.Math.Sin(a[i])) / 2; yPos[i] = yCen + (this.ClientRectangle.Height / 2) * System.Math.Cos(a[i]); } } else { xPos[i] = xCen + (this.ClientRectangle.Width / 2) * System.Math.Sin(a[i]); yPos[i] = yCen + (this.ClientRectangle.Height / 2) * System.Math.Cos(a[i]); } gBmp.DrawLine(penLine, (float)xCen, (float)yCen, (float)xPos[i], (float)yPos[i]); } } } // DEBUG: Draw the transform values: //gBmp.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.ClientRectangle.Width, 15); //gBmp.DrawString("Transform: x=" + xScl.ToString() + "/y=" + yScl.ToString() + " Offset: x=" + ((TextureBrush)backBrush).Transform.OffsetX + "/y=" + ((TextureBrush)backBrush).Transform.OffsetY + " Elements: " + AosConvert.ConcatArray(((TextureBrush)backBrush).Transform.Elements, ","), this.Font, SystemBrushes.ControlText, this.ClientRectangle.Location); backBrush.Dispose(); if (bgImg != null) bgImg.Dispose(); // Finally, create a Graphics object to draw the Bitmap to the control. using (Graphics g = this.CreateGraphics()) g.DrawImageUnscaled(bmp, new Point(0, 0)); } } } finally { this._drawing = false; } }
public override void Draw(Graphics g, int time) { if (BackgroundImage == null) { base.Draw(g, time); } else { if (base.DrawVisible) { Matrix matrix1 = base.Transform.Matrix.Clone(); GraphicsContainer container1 = g.BeginContainer(); g.SmoothingMode = base.OwnerDocument.SmoothingMode; Matrix matrix2 = base.GraphTransform.Matrix.Clone(); base.GraphTransform.Matrix.Multiply(matrix1, MatrixOrder.Prepend); ClipAndMask.ClipPath.Clip(g, time, this); bool flag1 = base.Visible; if (!base.Visible) { g.SetClip(Rectangle.Empty); } float single1 = this.Opacity; if (this.svgAnimAttributes.ContainsKey("fill-opacity")) { single1 = Math.Min(single1, (float)this.svgAnimAttributes["fill-opacity"]); } using (GraphicsPath path1 = (GraphicsPath)this.GPath.Clone()) { path1.Transform(base.GraphTransform.Matrix); if (!base.ShowBound) { ImageAttributes imageAttributes = new ImageAttributes(); ColorMatrix cmatrix1 = new ColorMatrix(); cmatrix1.Matrix00 = 1f; cmatrix1.Matrix11 = 1f; cmatrix1.Matrix22 = 1f; cmatrix1.Matrix33 = single1;//���� cmatrix1.Matrix44 = 1f; //�������� imageAttributes.SetColorMatrix(cmatrix1, ColorMatrixFlag.Default, ColorAdjustType.Default); TextureBrush tbush = new TextureBrush(BackgroundImage, new RectangleF(0, 0, image1.Width, image1.Height), imageAttributes); tbush.WrapMode = WrapMode.Tile; tbush.TranslateTransform(path1.PathPoints[0].X, path1.PathPoints[0].Y); tbush.ScaleTransform(matrix2.Elements[0] / 8, matrix2.Elements[0] / 8); //tbush.RotateTransform(45); g.FillPath(tbush, path1); ItopVector.Core.Paint.Stroke stroke1 = ItopVector.Core.Paint.Stroke.GetStroke(this); this.GraphStroke.Update(this, time); float penwidth = this.GraphStroke.StrokePen.Width * matrix2.Elements[0] / 6; using (Pen pen1 = new Pen(this.GraphStroke.StrokeColor, penwidth)) { g.DrawPath(pen1, path1); } //this.GraphStroke.Paint(g, this, path1, time); } else { g.DrawPath(new Pen(base.BoundColor), path1); } this.DrawConnect(g); } matrix1.Dispose(); ClipAndMask.ClipPath.DrawClip(g, time, this); g.EndContainer(container1); this.pretime = time; } } }