private void ResimOlustur(int genislik, int yukseklik) { Bitmap bitmap = new Bitmap(genislik, yukseklik, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, genislik, yukseklik); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(System.Drawing.FontFamily.GenericSerif.Name, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.Image = bitmap; }
void OnPaint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; HatchBrush hb = new HatchBrush(HatchStyle.Cross, Color.Black, this.BackColor); g.FillRectangle(hb, 10, 15, 90, 60); hb = new HatchBrush(HatchStyle.Percent05, Color.Black, this.BackColor); g.FillRectangle(hb, 130, 15, 90, 60); hb = new HatchBrush(HatchStyle.SolidDiamond, Color.Black, this.BackColor); g.FillRectangle(hb, 250, 15, 90, 60); hb = new HatchBrush(HatchStyle.DiagonalBrick, Color.Black, this.BackColor); g.FillRectangle(hb, 10, 105, 90, 60); hb = new HatchBrush(HatchStyle.Divot, Color.Black, this.BackColor); g.FillRectangle(hb, 130, 105, 90, 60); hb = new HatchBrush(HatchStyle.Wave, Color.Black, this.BackColor); g.FillRectangle(hb, 250, 105, 90, 60); hb = new HatchBrush(HatchStyle.ZigZag, Color.Black, this.BackColor); g.FillRectangle(hb, 10, 195, 90, 60); hb = new HatchBrush(HatchStyle.Sphere, Color.Black, this.BackColor); g.FillRectangle(hb, 130, 195, 90, 60); hb = new HatchBrush(HatchStyle.Shingle, Color.Black, this.BackColor); g.FillRectangle(hb, 250, 195, 90, 60); hb.Dispose(); g.Dispose(); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; HatchBrush hb = new HatchBrush(HatchStyle.HorizontalBrick, Color.Red, Color.Yellow); e.Graphics.FillEllipse(hb, 0, 80, 280, 120); hb.Dispose(); }
public void Clone_Disposed_ThrowsArgumentException() { var brush = new HatchBrush(HatchStyle.DarkHorizontal, Color.PeachPuff, Color.Purple); brush.Dispose(); AssertExtensions.Throws <ArgumentException>(null, () => brush.Clone()); }
public void BackgroundColor_EmptyAndGetDisposed_ThrowsArgumentException() { var brush = new HatchBrush(HatchStyle.DarkHorizontal, Color.PeachPuff, Color.Purple); brush.Dispose(); AssertExtensions.Throws <ArgumentException>(null, () => brush.BackgroundColor); }
private void AuraDesignForm_Disposed(object sender, EventArgs e) { if (Brush != null) { Brush.Dispose(); Brush = null; } hb.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { Bitmap B = new Bitmap(Width, Height); Graphics G = Graphics.FromImage(B); try { SelectedTab.BackColor = BackColor; } catch { } G.Clear(BackColor); for (int i = 0; i <= TabCount - 1; i++) { if (i == SelectedIndex) { Rectangle x2 = new Rectangle(GetTabRect(i).X - 2, GetTabRect(i).Y, GetTabRect(i).Width, GetTabRect(i).Height - 2); Rectangle x3 = new Rectangle(GetTabRect(i).X - 2, GetTabRect(i).Y, GetTabRect(i).Width, GetTabRect(i).Height - 1); Rectangle x4 = new Rectangle(GetTabRect(i).X - 2, GetTabRect(i).Y, GetTabRect(i).Width, GetTabRect(i).Height); LinearGradientBrush G1 = new LinearGradientBrush(x3, Color.FromArgb(10, 0, 0, 0), Color.FromArgb(35, 35, 35), 90f); HatchBrush HB = new HatchBrush(HatchStyle.LightDownwardDiagonal, Color.FromArgb(10, Color.Black), Color.Transparent); G.FillRectangle(HB, x3); HB.Dispose(); G.FillRectangle(G1, x3); G1.Dispose(); G.DrawLine(new Pen(Color.FromArgb(10, 10, 10)), x2.Location, new Point(x2.Location.X, x2.Location.Y + x2.Height)); G.DrawLine(new Pen(Color.FromArgb(10, 10, 10)), new Point(x2.Location.X + x2.Width, x2.Location.Y), new Point(x2.Location.X + x2.Width, x2.Location.Y + x2.Height)); G.DrawLine(new Pen(Color.FromArgb(10, 10, 10)), new Point(x2.Location.X, x2.Location.Y), new Point(x2.Location.X + x2.Width, x2.Location.Y)); G.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.DeepSkyBlue), x4, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); } else { Rectangle x2 = new Rectangle(GetTabRect(i).X - 2, GetTabRect(i).Y + 3, GetTabRect(i).Width, GetTabRect(i).Height - 5); LinearGradientBrush G1 = new LinearGradientBrush(x2, Color.FromArgb(30, 30, 30), Color.FromArgb(35, 35, 35), -90f); G.FillRectangle(G1, x2); G1.Dispose(); G.DrawRectangle(new Pen(Color.FromArgb(15, 15, 15)), x2); G.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.FromArgb(75, 75, 75)), x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); } } G.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(10, 10, 10))), new Rectangle(0, 21, Width - 1, Height - 22)); e.Graphics.DrawImage((Bitmap)B.Clone(), 0, 0); G.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1)); G.Dispose(); B.Dispose(); }
private void GenerateImage() { Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(this.familyName, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); }while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.image = bitmap; }
private void button4_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); HatchBrush hBrush = new HatchBrush(HatchStyle.Plaid, Color.Red); g.FillRectangle(hBrush, 10, 10, 240, 150); hBrush.Dispose(); g.Dispose(); }
private void ApplyBtn_Click(object sender, System.EventArgs e) { // Create a Graphics object Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); // Read curretnt style from combo box string str = comboBox1.Text; // Find out the style and set it as the // current style switch (str) { case "BackwardDiagonal": style = HatchStyle.BackwardDiagonal; break; case "DashedVertical": style = HatchStyle.DashedVertical; break; case "Cross": style = HatchStyle.Cross; break; case "DiagonalCross": style = HatchStyle.DiagonalCross; break; case "HorizontalBrick": style = HatchStyle.HorizontalBrick; break; case "LightDownwardDiagonal": style = HatchStyle.LightDownwardDiagonal; break; case "LightUpwardDiagonal": style = HatchStyle.LightUpwardDiagonal; break; default: break; } // Create a hatch brush with selected // hatch style and colors HatchBrush brush = new HatchBrush(style, forClr, backClr); // fill rectangle g.FillRectangle(brush, 50, 100, 200, 200); // Dispose brush.Dispose(); g.Dispose(); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; HatchBrush mybrush = new HatchBrush(HatchStyle.DarkVertical, Color.White, Color.Violet); Pen mypen = new Pen(mybrush, 5); g.DrawEllipse(mypen, 10, 10, 200, 200); mypen.Dispose(); mybrush.Dispose(); }
private void GenerateImage() { Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bitmap); graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rectangle = new Rectangle(0, 0, this.width, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); graphics.FillRectangle(hatchBrush, rectangle); float num = (float)(rectangle.Height + 1); Font font; do { num -= 1f; font = new Font(FontFamily.GenericSansSerif, num, FontStyle.Bold); }while (graphics.MeasureString(this.text, font).Width > (float)rectangle.Width); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddString(this.text, font.FontFamily, (int)font.Style, this.fontSize, rectangle, stringFormat); float num2 = 4f; PointF[] destPoints = new PointF[] { new PointF((float)this.random.Next(rectangle.Width) / num2, (float)this.random.Next(rectangle.Height) / num2), new PointF((float)rectangle.Width - (float)this.random.Next(rectangle.Width) / num2, (float)this.random.Next(rectangle.Height) / num2), new PointF((float)this.random.Next(rectangle.Width) / num2, (float)rectangle.Height - (float)this.random.Next(rectangle.Height) / num2), new PointF((float)rectangle.Width - (float)this.random.Next(rectangle.Width) / num2, (float)rectangle.Height - (float)this.random.Next(rectangle.Height) / num2) }; Matrix matrix = new Matrix(); matrix.Translate(0f, 0f); graphicsPath.Warp(destPoints, rectangle, matrix, WarpMode.Perspective, 0f); hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.SkyBlue); graphics.FillPath(hatchBrush, graphicsPath); int num3 = Math.Max(rectangle.Width, rectangle.Height); for (int i = 0; i < (int)((float)(rectangle.Width * rectangle.Height) / 30f); i++) { int x = this.random.Next(rectangle.Width); int y = this.random.Next(rectangle.Height); int num4 = this.random.Next(num3 / 50); int num5 = this.random.Next(num3 / 50); graphics.FillEllipse(hatchBrush, x, y, num4, num5); } font.Dispose(); hatchBrush.Dispose(); graphics.Dispose(); this.image = bitmap; }
protected void Page_Load(object sender, EventArgs e) { Bitmap bmp = new Bitmap(Server.MapPath("~\\images\\captcha2.jpg")); MemoryStream memStream = new MemoryStream(); int width = bmp.Width; int height = bmp.Height; string familyName = "Arial"; string captchaText = Request.Cookies["Captcha"]["value"]; Bitmap bitmap = new Bitmap(bmp, new Size(width, height)); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; int xCopyright = width - 150; int yCopyright = height - 50; Rectangle rect; Font font; int newfontsize = 45; font = new Font(familyName, newfontsize, FontStyle.Italic); rect = new Rectangle(xCopyright, yCopyright, 0, 0); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; GraphicsPath path = new GraphicsPath(); path.AddString(captchaText, font.FontFamily, (int)font.Style, font.Size, rect, format); HatchBrush hatchBrush = new HatchBrush( HatchStyle.LargeConfetti, Color.FromName("White"), Color.FromName("Black")); g.FillPath(hatchBrush, path); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "image/jpeg"; bitmap.Save(memStream, ImageFormat.Jpeg); bmp.Dispose(); font.Dispose(); hatchBrush.Dispose(); g.Dispose(); memStream.WriteTo(HttpContext.Current.Response.OutputStream); bitmap.Dispose(); }
/// <summary> /// based on code from https://thecodeprogram.com/build-your-own-captcha-in-asp-net-and-c- /// </summary> /// <param name="code"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static Bitmap GenerateCaptchaImage(string code, int width = 350, int height = 80) { Random rnd = new Random(); //First declare a bitmap and declare graphic from this bitmap Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); //And create a rectangle to delegete this image graphic Rectangle rect = new Rectangle(0, 0, width, height); //And create a brush to make some drawings HatchBrush hatchBrush = new HatchBrush(HatchStyle.DottedGrid, Color.Aqua, Color.White); g.FillRectangle(hatchBrush, rect); // Randomize colors var colors = new Color[] { Color.LightGreen, Color.LightSalmon, Color.LightSkyBlue, Color.LightCyan }; for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { using (var dotsBrush = new HatchBrush(HatchStyle.Percent10, foreColor: Color.Black, backColor: colors[rnd.Next(colors.Length)])) { int x = rnd.Next(width + 5) - 5; int y = rnd.Next(height + 5) - 5; int w = 3 + rnd.Next(10); int h = 3 + rnd.Next(10); g.FillEllipse(dotsBrush, x, y, w, h); } } //here we make the text configurations GraphicsPath graphicPath = new GraphicsPath(); //add this string to image with the rectangle delegate graphicPath.AddString(" " + code, FontFamily.GenericMonospace, (int)FontStyle.Bold, 75, rect, null); //And the brush that you will write the text hatchBrush = new HatchBrush(HatchStyle.Percent20, Color.White, Color.Teal); g.FillPath(hatchBrush, graphicPath); var linePen = new Pen(color: Color.Teal, width: 2.0f); for (int i = 0; i < 10; i++) { int x1 = rnd.Next(width); int y1 = rnd.Next(height); int x2 = rnd.Next(width); int y2 = rnd.Next(height); g.DrawLine(linePen, x1, y1, x2, y2); } hatchBrush.Dispose(); linePen.Dispose(); g.Dispose(); return(bitmap); }
protected override Image CreateImage() { var res = new Bitmap(Width, Height); using (var g = Graphics.FromImage(res)) { g.SmoothingMode = SmoothingMode.HighQuality; for (var row = 0; row < _cellRows; row++) { for (var col = 0; col < _cellColumns; col++) { var c = Cells[row][col]; if (c.FillColor.A != 255) { var hb = new HatchBrush(HatchStyle.SmallCheckerBoard, System.Drawing.Color.Black, System.Drawing.Color.White); switch (CellStyle) { case ColorCellStyle.Hexagon: c.DrawHexagon(g, new Pen(System.Drawing.Color.Transparent), hb); break; case ColorCellStyle.Circle: c.DrawCircle(g, new Pen(System.Drawing.Color.Transparent), hb); break; case ColorCellStyle.Square: c.DrawSquare(g, new Pen(System.Drawing.Color.Transparent), hb); break; } hb.Dispose(); } switch (CellStyle) { case ColorCellStyle.Hexagon: c.DrawHexagon(g); break; case ColorCellStyle.Circle: c.DrawCircle(g); break; case ColorCellStyle.Square: c.DrawSquare(g); break; } } } } return(res); }
//****************************************************** private void DrawLast(Graphics g) { if (currentPage == m_PageCount) { float t, l, h; int ff = (m_FrameCount % m_PageFrame); HatchBrush hb = new HatchBrush(HatchStyle.Percent30, Color.Black, Color.White); try { h = _CellHeight * 3; if (m_Sheet3 == false) { if (ff == 0) { t = _GridTop + _CellHeight * m_PageFrame / 2; l = _CellLeftR; } else if (ff <= m_PageFrameH) { t = _GridTop + ff * _CellHeight; l = _CellLeftL; } else { ff = ff - m_PageFrameH; t = _GridTop + ff * _CellHeight; l = _CellLeftR; } g.FillRectangle(hb, new RectangleF(m_mX + l, m_mY + t, _CellRectWidth, h)); } else { if (ff == 0) { t = _GridTop + _CellHeight * m_PageFrame; l = _CellLeftL; } else { t = _GridTop + ff * _CellHeight; l = _CellLeftL; } g.FillRectangle(hb, new RectangleF(m_mX + l, m_mY + t, _SheetWidth, h)); } } finally { hb.Dispose(); } } }
public override void Draw(Graphics g) { Pen pen; Brush b = new SolidBrush(FillColor); Brush b1 = new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255)); Brush b2 = new HatchBrush(HatchStyle.Cross, Color.Azure); Brush b3 = new TextureBrush(FillImage); if (DrawPen == null) { pen = new Pen(Color, PenWidth); } else { pen = (Pen)DrawPen.Clone(); } GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(GetNormalizedRectangle(Rectangle)); if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } g.DrawPath(pen, gp); if (Filled) { g.FillPath(b, gp); } if (Gradient) { g.FillPath(b1, gp); } if (Hatch) { g.FillPath(b2, gp); } if (Texture) { g.FillPath(b3, gp); } gp.Dispose(); pen.Dispose(); b.Dispose(); b1.Dispose(); b2.Dispose(); b3.Dispose(); }
public static void SyncBrushes() { hoverBrush.Dispose(); hoverBrush = new SolidBrush(Color.FromArgb(50, SystemColors.Highlight)); selectionBorderBrush.Dispose(); selectionBorderBrush = new HatchBrush(HatchStyle.Percent50, SystemColors.ControlDarkDark, Color.Transparent); System.Design.SafeNativeMethods.DeleteObject(new HandleRef(null, grabHandleFillBrushPrimary)); grabHandleFillBrushPrimary = System.Design.SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(SystemColors.Window)); System.Design.SafeNativeMethods.DeleteObject(new HandleRef(null, grabHandleFillBrush)); grabHandleFillBrush = System.Design.SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(SystemColors.ControlText)); System.Design.SafeNativeMethods.DeleteObject(new HandleRef(null, grabHandlePenPrimary)); grabHandlePenPrimary = System.Design.SafeNativeMethods.CreatePen(System.Design.NativeMethods.PS_SOLID, 1, ColorTranslator.ToWin32(SystemColors.ControlText)); System.Design.SafeNativeMethods.DeleteObject(new HandleRef(null, grabHandlePen)); grabHandlePen = System.Design.SafeNativeMethods.CreatePen(System.Design.NativeMethods.PS_SOLID, 1, ColorTranslator.ToWin32(SystemColors.Window)); }
public override void Draw2D(sc2i.drawing.CContextDessinObjetGraphique contexte, EFaceVueDynamique faceVisible, System.Drawing.Size sizeReference) { I2iObjetGraphique rect = Get2D(faceVisible); Brush br = new HatchBrush(HatchStyle.Divot, ForeColor, Color.FromArgb(50, BackColor)); Rectangle rct = CUtilRect.Normalise(rect.RectangleAbsolu); contexte.Graphic.FillRectangle(br, rct); br.Dispose(); contexte.Graphic.DrawRectangle(Pens.Beige, rct); foreach (C2iComposant3D fils in SortChildsFor2D(faceVisible)) { fils.Draw2D(contexte, faceVisible, sizeReference); } }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); foreach (var pen in _pens) { pen.Dispose(); } _hatchBrush.Dispose(); _gradientBrush.Dispose(); } base.Dispose(disposing); }
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { // Create brushes and pens HatchBrush hatchBrush = new HatchBrush(HatchStyle.HorizontalBrick, Color.Red, Color.Blue); Pen redPen = new Pen(Color.Red, 2); Pen hatchPen = new Pen(hatchBrush, 4); SolidBrush brush = new SolidBrush(Color.Green); // Create points for curve. PointF p1 = new PointF(40.0F, 50.0F); PointF p2 = new PointF(60.0F, 70.0F); PointF p3 = new PointF(80.0F, 34.0F); PointF p4 = new PointF(120.0F, 180.0F); PointF p5 = new PointF(200.0F, 150.0F); PointF[] ptsArray = { p1, p2, p3, p4, p5 }; float x = 5.0F, y = 5.0F; float width = this.ClientRectangle.Width - 100; float height = this.ClientRectangle.Height - 100; Point pt1 = new Point(40, 30); Point pt2 = new Point(80, 100); Color [] lnColors = { Color.Black, Color.Red }; LinearGradientBrush lgBrush = new LinearGradientBrush (pt1, pt2, Color.Red, Color.Green); lgBrush.LinearColors = lnColors; lgBrush.GammaCorrection = true; // Draw objects e.Graphics.DrawPolygon(redPen, ptsArray); e.Graphics.DrawRectangle(hatchPen, x, y, width, height); e.Graphics.FillRectangle(lgBrush, 200, 200, 200, 200); // Dispose lgBrush.Dispose(); brush.Dispose(); hatchPen.Dispose(); redPen.Dispose(); hatchBrush.Dispose(); }
public override void DrawSelection(Graphics g) { const int border = 3; var r = BaseElement.GetUnsignedRectangle( new Rectangle( El.Location.X - border, El.Location.Y - border, El.Size.Width + (border * 2), El.Size.Height + (border * 2))); var brush = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightGray, Color.Transparent); var p = new Pen(brush, border); g.DrawEllipse(p, r); p.Dispose(); brush.Dispose(); }
public static Bitmap GetCaptchaImage(Color fg, Color bg, Color n) { int topPadding = 2; // top and bottom padding in pixels int sidePadding = 3; // side padding in pixels SolidBrush textBrush = new SolidBrush(fg); Font font = new Font(FontFamily.GenericSansSerif, 32, FontStyle.Bold); string guid = GetKey(); Bitmap bmpCaptcha = new Bitmap(500, 500); Graphics graphics = Graphics.FromImage(bmpCaptcha); SizeF textSize = graphics.MeasureString(guid, font); bmpCaptcha.Dispose(); graphics.Dispose(); int bitmapWidth = sidePadding * 2 + (int)textSize.Width; int bitmapHeight = topPadding * 2 + (int)textSize.Height; bmpCaptcha = new Bitmap(bitmapWidth, bitmapHeight); graphics = Graphics.FromImage(bmpCaptcha); Rectangle rect = new Rectangle(0, 0, bmpCaptcha.Width, bmpCaptcha.Height); HatchBrush hatch1 = new HatchBrush(HatchStyle.SmallGrid, n, bg); HatchBrush hatch2 = new HatchBrush(HatchStyle.DiagonalCross, bg, Color.Transparent); graphics.FillRectangle(hatch1, rect); graphics.DrawString(guid, font, textBrush, sidePadding, topPadding); graphics.FillRectangle(hatch2, rect); HttpContext.Current.Response.ContentType = "image/x-png"; using (MemoryStream memStream = new MemoryStream()) { bmpCaptcha.Save(memStream, ImageFormat.Png); } textBrush.Dispose(); font.Dispose(); hatch1.Dispose(); hatch2.Dispose(); graphics.Dispose(); return(bmpCaptcha); }
private void OnPaint(object sender, PaintEventArgs e) { Graphics formGraphics = this.CreateGraphics(); formGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Pen myPen; myPen = new Pen(Color.Red, 2); formGraphics.DrawRectangle(myPen, new Rectangle(0, 0, 200, 300)); formGraphics.FillRectangle(Brushes.Orange, new Rectangle(25, 50, 100, 200)); myPen.Width = 1; myPen.DashStyle = DashStyle.DashDot; formGraphics.DrawRectangle(myPen, new Rectangle(1, 1, 50, 50)); Brush myBrush; myBrush = new HatchBrush(HatchStyle.SolidDiamond, Color.Red, Color.Black); formGraphics.FillRectangle(myBrush, new Rectangle(50, 50, 100, 100)); LinearGradientBrush gradient = new LinearGradientBrush(new Rectangle(0, 0, 100, 100), Color.Blue, Color.Yellow, LinearGradientMode.ForwardDiagonal); formGraphics.FillEllipse(gradient, new Rectangle(50, 150, 100, 100)); //Pacman !!!! Brush myBrush2; myBrush2 = new SolidBrush(Color.Yellow); formGraphics.FillPie(myBrush2, new Rectangle(25, 0, 100, 100), 45, 270); Font drawFont = new Font("Arial", 16); formGraphics.DrawString("PACMAN", drawFont, gradient, 100, 250); drawFont.Dispose(); myBrush2.Dispose(); myBrush.Dispose(); myPen.Dispose(); formGraphics.Dispose(); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } _horizontalBrickBrush.Dispose(); _diagonalBrickBrush.Dispose(); _diagonalThinBricks.Dispose(); _diagonalThickBricks.Dispose(); _horizontalThinBricks.Dispose(); _horizontalThickBricks.Dispose(); } base.Dispose(disposing); }
protected override void OnPaint(PaintEventArgs pe) { // TODO: 在此处添加自定义绘制代码 Graphics g = pe.Graphics; GraphicsPath path = new GraphicsPath(); Rectangle rc = new Rectangle(0, 0, this.ClientSize.Width - 1, this.ClientSize.Height - 1); path.AddEllipse(rc); Brush bsh = null; switch (FillPattern) { case FillPatternStyle.Color: bsh = new SolidBrush(FillColor); break; case FillPatternStyle.Hatch: bsh = new HatchBrush(HatchStyle, FillColor); break; } if (bsh != null) { g.FillPath(bsh, path); bsh.Dispose(); } // Draw Pen pen = null; pen = new Pen(Color.FromArgb(LineAlpha, LineColor)); pen.Width = LineWidth; pen.DashStyle = DashStyle; g.DrawPath(pen, path); if (pen != null) { pen.Dispose(); } path.Dispose(); // 调用基类 OnPaint base.OnPaint(pe); }
public override void DrawSelection(System.Drawing.Graphics g) { Color selColor = Color.Red; int border = 3; Rectangle r = BaseElement.GetUnsignedRectangle( new Rectangle( el.Location.X - border, el.Location.Y - border, el.Size.Width + (border * 2), el.Size.Height + (border * 2))); HatchBrush brush = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightGray, Color.Transparent); Pen p = new Pen(brush, border); g.DrawEllipse(p, r); p.Dispose(); brush.Dispose(); }
/// <summary> /// 給干擾圖 /// </summary> /// <param name="g">畫布</param> /// <param name="lines">干擾線數量</param> private void InterferenceImage(ref Graphics g) { int m = Math.Max(imageWidth, imageHeight); // Draw the text. var hatchBrush = new HatchBrush( HatchStyle.LargeConfetti, Color.White, Color.Black); for (int i = 0; i < (int)(imageWidth * imageHeight / 30F); i++) { int x = random.Next(imageWidth); int y = random.Next(imageHeight); int w = random.Next(m / 50); int h = random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } hatchBrush.Dispose(); }
private void GenerateImage() { var bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb); var graphics = Graphics.FromImage(bitmap); graphics.SmoothingMode = SmoothingMode.AntiAlias; var rect = new Rectangle(0, 0, Width, Height); var brush = new LinearGradientBrush(rect, Color.Yellow, Color.Orange, 2f); graphics.FillRectangle(brush, rect); var font = CreateFont(rect, graphics); var format = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; var path = new GraphicsPath(); path.AddString(Text, font.FontFamily, (int)font.Style, font.Size, rect, format); var hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.DarkBlue, Color.CornflowerBlue); graphics.FillPath(hatchBrush, path); var m = Math.Max(rect.Width, rect.Height); for (var i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { var x = random.Next(rect.Width); var y = random.Next(rect.Height); var w = random.Next(m / 40); var h = random.Next(m / 40); graphics.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); graphics.Dispose(); Image = bitmap; }
protected override void OnPaint(PaintEventArgs e) { if (base.DesignMode) { Graphics gr = e.Graphics; HatchBrush hb = null; Pen p = null; try { switch (this.FileDlgStartLocation) { case AddonWindowLocation.Right: hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Black, Color.Red); p = new Pen(hb, 5f); gr.DrawLine(p, 0, 0, 0, base.Height); goto IL_CF; case AddonWindowLocation.Bottom: hb = new HatchBrush(HatchStyle.NarrowVertical, Color.Black, Color.Red); p = new Pen(hb, 5f); gr.DrawLine(p, 0, 0, base.Width, 0); goto IL_CF; } hb = new HatchBrush(HatchStyle.Sphere, Color.Black, Color.Red); p = new Pen(hb, 5f); gr.DrawLine(p, 0, 0, 4, 4); } finally { if (p != null) { p.Dispose(); } if (hb != null) { hb.Dispose(); } } } IL_CF: base.OnPaint(e); }
/// <summary> /// Paints a representation of the value of an object using the specified PaintValueEventArgs. /// </summary> /// <param name="e">A PaintValueEventArgs that indicates what to paint and where to paint it.</param> public override void PaintValue(PaintValueEventArgs e) { if (e.Value != null) { HatchStyle style = (HatchStyle)e.Value; Rectangle bounds = e.Bounds; Brush brush = new HatchBrush(style, SystemColors.WindowText, SystemColors.Window); try { GraphicsState state = e.Graphics.Save(); e.Graphics.RenderingOrigin = new Point(bounds.X, bounds.Y); e.Graphics.FillRectangle(brush, bounds); e.Graphics.Restore(state); } finally { brush.Dispose(); } } }
public virtual void DrawSelection(Graphics g) { int border = 3; Point elLocation = el.Location; Size elSize = el.Size; Rectangle r = BaseElement.GetUnsignedRectangle( new Rectangle( elLocation.X - border, elLocation.Y - border, elSize.Width + (border * 2), elSize.Height + (border * 2))); HatchBrush brush = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightGray, Color.Transparent); Pen p = new Pen(brush, border); g.DrawRectangle(p, r); p.Dispose(); brush.Dispose(); }
// ==================================================================== // Creates the bitmap image. // ==================================================================== private void GenerateImage() { // Create a new 32-bit bitmap image. Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb); // Create a graphics object for drawing. Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); // Fill in the background. HatchBrush hatchBrush = new HatchBrush(HatchStyle.OutlinedDiamond, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); // Set up the text font. SizeF size; float fontSize = rect.Height + 1; Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new Font(this.familyName, fontSize, FontStyle.Strikeout); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); // Draw the text. hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); // Add some random noise. int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } // Clean up. font.Dispose(); hatchBrush.Dispose(); g.Dispose(); // Set the image. this.image = bitmap; }
private void HandlePaint(Object sender, PaintEventArgs e) { Graphics graphics = e.Graphics; Form form = (sender as Form); Rectangle bounds = form.ClientRectangle; Pen pen = new Pen(Color.Black, 1.0f); graphics.DrawLine(pen, 0, 0, bounds.Width, bounds.Height - 23); pen.Dispose(); pen = new Pen(Color.Red, 2.0f); graphics.DrawRectangle (pen, 10, 10, bounds.Width - 20, bounds.Height - 40); pen.Dispose(); ControlPaint.DrawFocusRectangle (graphics, new Rectangle(15, 15, bounds.Width - 30, bounds.Height - 50)); Brush brush = new SolidBrush(Color.Yellow); graphics.FillPie(brush, 20, 20, 60, 60, 30.0f, 70.0f); brush.Dispose(); Font font = new Font("Arial", 12); brush = new SolidBrush(Color.Blue); graphics.DrawString("Hello", font, brush, 30, 100); brush.Dispose(); font.Dispose(); brush = new HatchBrush (HatchStyle.BackwardDiagonal, Color.Black, Color.White); graphics.FillEllipse(brush, 200, 40, 100, 100); brush.Dispose(); }
private void GenerateImage() { Bitmap bitmap = new Bitmap (this.width, this.height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.White, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); //path.AddString(this.text, font.FontFamily, (int) font.Style, // font.Size, rect, format); path.AddString(this.text, font.FontFamily, (int)font.Style, 30, rect, format); //float v = 4F; //PointF[] points = // { // new PointF(this.random.Next(rect.Width) / v, this.random.Next( // rect.Height) / v), // new PointF(rect.Width - this.random.Next(rect.Width) / v, // this.random.Next(rect.Height) / v), // new PointF(this.random.Next(rect.Width) / v, // rect.Height - this.random.Next(rect.Height) / v), // new PointF(rect.Width - this.random.Next(rect.Width) / v, // rect.Height - this.random.Next(rect.Height) / v) // }; //Matrix matrix = new Matrix(); //matrix.Translate(0F, 0F); //path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.CornflowerBlue); g.FillPath(hatchBrush, path); //int m = Math.Max(rect.Width, rect.Height); //for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) //{ // int x = this.random.Next(rect.Width); // int y = this.random.Next(rect.Height); // int w = this.random.Next(m / 50); // int h = this.random.Next(m / 50); // g.FillEllipse(hatchBrush, x, y, w, h); //} font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.image = bitmap; }