void EDSToolTip_Draw(object sender, DrawToolTipEventArgs e) { if (e.ToolTipText.Trim() != "") { //e.DrawBackground(); Graphics g = e.Graphics; //draw background LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(Point.Empty, e.Bounds.Size), Color.FromArgb(250, 252, 253), Color.FromArgb(206, 220, 240), LinearGradientMode.Vertical); g.FillRectangle(lgb, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); lgb.Dispose(); //Console.WriteLine(e.ToolTipText); //draw border ControlPaint.DrawBorder(g, e.Bounds, SystemColors.GrayText, ButtonBorderStyle.Dashed); //draw Image g.DrawImage(image, new Point(5, 5)); // Draw the custom text. // The using block will dispose the StringFormat automatically. using (StringFormat sf = new StringFormat()) { using (Font f = new Font("Tahoma", 8)) { e.Graphics.DrawString(e.ToolTipText, f, Brushes.Black, e.Bounds.X + 25, e.Bounds.Y + 30, StringFormat.GenericTypographic); } } } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; g.Clear(this.Parent.BackColor); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(Point.Empty, e.ClipRectangle.Size); rect.Width -= 1; rect.Height -= 1; Color coutBorder; Color cinnerBorder; Color cbackgroundTop; Color cbackgroundBottom; Color ctext; if (mouseover) { coutBorder = ButtonColor.HoverOutBorder; cinnerBorder = ButtonColor.HoverInnerBorder; cbackgroundTop = ButtonColor.HoverBackgroundTop; cbackgroundBottom = ButtonColor.HoverBackgroundBottom; ctext = mousedown ? Color.Black : ButtonColor.HoverText; } else { coutBorder = ButtonColor.OutBorder; cinnerBorder = ButtonColor.InnerBorder; cbackgroundTop = ButtonColor.BackgroundTop; cbackgroundBottom = ButtonColor.BackgroundBottom; ctext = ButtonColor.Text; } using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(rect, 2)) { using (LinearGradientBrush lgBrush = new LinearGradientBrush(Point.Empty, new Point(rect.Width, rect.Height), cbackgroundTop, cbackgroundBottom)) { g.FillPath(lgBrush, path); } g.DrawPath(new Pen(coutBorder), path); rect.Inflate(-1, -1); using (GraphicsPath path2 = GraphicsTools.CreateRoundRectangle(rect, 2)) { g.DrawPath(new Pen(cinnerBorder), path2); } } StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; g.DrawString(this.Text, this.Font, new SolidBrush(ctext), e.ClipRectangle, sf); UpdateBounds(this.Location.X, this.Location.Y, this.Width, this.Height, e.ClipRectangle.Width, e.ClipRectangle.Height); }
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡι��캯�� public VerifyPictureMaker(int width, int height, PictureBox target) { m_obPic = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(m_obPic); g.Clear(Color.White); if (target != null) { target.Width = width; target.Height = height; target.Image = m_obPic; } //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡα������� for (int i = 0; i < 25; i++) { int x1 = m_obRandom.Next(m_obPic.Width); int x2 = m_obRandom.Next(m_obPic.Width); int y1 = m_obRandom.Next(m_obPic.Height); int y2 = m_obRandom.Next(m_obPic.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ��ַ����� Font font = new Font("Arial", 12, (FontStyle.Bold | FontStyle.Italic)); string code = getVerifyCode(5); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, m_obPic.Width, m_obPic.Height), Color.Blue, Color.DarkRed, 1.2f, true); g.DrawString(code, font, brush, 2, 0); //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ�ǰ������ for (int i = 0; i < 100; i++) { int x = m_obRandom.Next(m_obPic.Width); int y = m_obRandom.Next(m_obPic.Height); m_obPic.SetPixel(x, y, Color.FromArgb(m_obRandom.Next())); } }
void GDIpLines_Paint(object sender, PaintEventArgs e) { var lines = LineInfo.GenerateRandom(new Rectangle(Point.Empty, this.ClientSize)); var sw = new Stopwatch(); sw.Start(); var g = e.Graphics; g.Clear(Color.Black); foreach (var line in lines) { using (var b = new LinearGradientBrush(line.Pa, line.Pb, line.Ca, line.Cb)) using (var p = new Pen(b, 1f)) { g.DrawLine(p, line.Pa, line.Pb); } } sw.Stop(); Program.Info( "{0}: {1} [ms], {2} [line], {3:.00} [line/ms], {4} * {5}", this.Text, sw.ElapsedMilliseconds, lines.Length, lines.Length / (float)sw.ElapsedMilliseconds, this.ClientSize.Width, this.ClientSize.Height ); }
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { try { p.Width = 6; Rectangle r = this.ClientRectangle; // r.Width--; r.Height--; using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius)) { using (System.Drawing.Drawing2D.LinearGradientBrush gradBrush = new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 90, false)) { ColorBlend cb = new ColorBlend(); cb.Positions = new[] { 0, 1f }; cb.Colors = new[] { Color.Transparent, Color.Transparent }; gradBrush.InterpolationColors = cb; // rotate gradBrush.RotateTransform(0); // paint //g.FillPath(gradBrush, rr); g.DrawPath(p, rr); } } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public void DrawFormBackgroud(Graphics g, Rectangle r) { drawing = new Bitmap(this.Width, this.Height, g); gg = Graphics.FromImage(drawing); Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10); Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, 42); //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 41, 61), Color.FromArgb(47, 64, 94), LinearGradientMode.Vertical); LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical); //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical); LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend(); // Set multi-color gradient blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 1.0f }; //blend.Colors = new[] { Color.FromArgb(47, 64, 94), Color.FromArgb(64, 88, 126), Color.FromArgb(66, 90, 129), Color.FromArgb(64, 88, 126), Color.FromArgb(49, 66, 95) }; blend.Colors = new[] { Color.FromArgb(47,colorR, 64), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(66, colorR+35, 90), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(49, colorR+1, 66) }; grad.InterpolationColors = blend; Font myf=new System.Drawing.Font(this.Font.FontFamily,16); // Draw basic gradient and shadow //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gg.FillRectangle(grad, gradRect); gg.FillRectangle(shadow, shadowRect); gg.DrawString("Добавить один ПК", myf, Brushes.GhostWhite, new PointF(55, 15)); gg.DrawImage(Properties.Resources.singleAdd1.ToBitmap(), 10, 10,32,32); g.DrawImageUnscaled(drawing, 0, 0); gg.Dispose(); // Draw checkers //g.FillRectangle(checkers, r); }
protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e) { // base.OnRenderSeparator(e); if (!e.Item.IsOnDropDown) { int top = 9; int left = e.Item.Width / 2; left--; int height = e.Item.Height - top * 2; RectangleF separator = new RectangleF(left, top, 0.5f, height); using (LinearGradientBrush b = new LinearGradientBrush( separator.Location, new Point(Convert.ToInt32(separator.Left), Convert.ToInt32(separator.Bottom)), Color.Red, Color.Black)) { ColorBlend blend = new ColorBlend(); blend.Colors = new Color[] { ToolStripColorTable.ToolStripSplitButtonTop, ToolStripColorTable.ToolStripSplitButtonMiddle, ToolStripColorTable.ToolStripSplitButtonMiddle, ToolStripColorTable.ToolStripSplitButtonBottom }; blend.Positions = new float[] { 0.0f, 0.22f, 0.78f, 1.0f }; b.InterpolationColors = blend; e.Graphics.FillRectangle(b, separator); } } }
public override Bitmap Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { int width = matrix.Width; int height = matrix.Height; var backgroundBrush = new LinearGradientBrush( new Rectangle(0, 0, width, height), BackgroundGradientColor, Background, LinearGradientMode.Vertical); var foregroundBrush = new LinearGradientBrush( new Rectangle(0, 0, width, height), ForegroundGradientColor, Foreground, LinearGradientMode.ForwardDiagonal); var bmp = new Bitmap(width, height); var gg = Graphics.FromImage(bmp); gg.Clear(Background); for (int x = 0; x < width - 1; x++) { for (int y = 0; y < height - 1; y++) { if (matrix[x, y]) { gg.FillRectangle(foregroundBrush, x, y, 1, 1); } else { gg.FillRectangle(backgroundBrush, x, y, 1, 1); } } } return bmp; }
protected override void OnPaint(PaintEventArgs pea) { base.OnPaint(pea); Graphics grfx = pea.Graphics; LinearGradientBrush lgbrush = null; Font font = new Font(this.Font.FontFamily, this.Font.Size, this.Font.Style); SolidBrush brush = new SolidBrush(this.ForeColor); int cw = (this.Width - 20)/7; int ch = this.Height - 20; for(int i = 0 ; i < 7; i++) { Rectangle temp = new Rectangle(10+(i*cw), 10, cw, ch ); if(i < 6) lgbrush = new LinearGradientBrush(temp, colors[i], colors[i+1], LinearGradientMode.Horizontal); else lgbrush = new LinearGradientBrush(temp, colors[i], colors[0], LinearGradientMode.Horizontal); lgbrush.WrapMode = WrapMode.Tile; grfx.FillRectangle(lgbrush, 10+(i*cw), 10, cw, ch ); } grfx.DrawString(this.Text, font, brush, this.Width/3, this.Height/2); }
public static void DrawRoundedRectangle(Graphics newGraphics, Color boxColor, Color gradFillColor1, Color gradFillColor2, int xPosition, int yPosition, int height, int width, int cornerRadius) { using (var boxPen = new Pen(boxColor)) { using (var path = new GraphicsPath()) { path.AddLine(xPosition + cornerRadius, yPosition, xPosition + width - (cornerRadius * 2), yPosition); path.AddArc(xPosition + width - (cornerRadius * 2), yPosition, cornerRadius * 2, cornerRadius * 2, 270, 90); path.AddLine(xPosition + width, yPosition + cornerRadius, xPosition + width, yPosition + height - (cornerRadius * 2)); path.AddArc(xPosition + width - (cornerRadius * 2), yPosition + height - (cornerRadius * 2), cornerRadius * 2, cornerRadius * 2, 0, 90); path.AddLine(xPosition + width - (cornerRadius * 2), yPosition + height, xPosition + cornerRadius, yPosition + height); path.AddArc(xPosition, yPosition + height - (cornerRadius * 2), cornerRadius * 2, cornerRadius * 2, 90, 90); path.AddLine(xPosition, yPosition + height - (cornerRadius * 2), xPosition, yPosition + cornerRadius); path.AddArc(xPosition, yPosition, cornerRadius * 2, cornerRadius * 2, 180, 90); path.CloseFigure(); newGraphics.DrawPath(boxPen, path); var b = new LinearGradientBrush(new Point(xPosition, yPosition), new Point(xPosition + width, yPosition + height), gradFillColor1, gradFillColor2); newGraphics.FillPath(b, path); } } }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Rectangle bounds = this.ClientRectangle; float percent = this.Percent; bounds.Width = (int)(bounds.Width * percent); PointF p1 = new PointF(0, 0); PointF p2 = new PointF(bounds.Width, 0); PointF p3 = new PointF(bounds.Width, bounds.Height / 2); PointF p4 = new PointF(0, bounds.Height / 2); g.ResetClip(); g.Clear(this.BackColor); if ((bounds.Width != 0) && (bounds.Height != 0)) //using (PathGradientBrush b = new PathGradientBrush(new PointF[] { p1, p2, p3, p4 }, WrapMode.TileFlipY)) //{ // b.CenterColor = Color.Gray; // b.SurroundColors = new Color[] { Color.Transparent, Color.Transparent, Color.Turquoise, Color.Turquoise }; // g.FillRectangle(b, bounds); //} using (LinearGradientBrush b = new LinearGradientBrush(p1, p2, Color.Red, Color.Blue)) { g.FillRectangle(b, bounds); } g.Flush(); }
public override void Render(Graphics g) { //theCode, love theVariableNames :D [Xylem] //Set the hue shades with the correct saturation and luminance Color[] theColors = { new ColorManager.HSVColor(0, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), new ColorManager.HSVColor(60, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), new ColorManager.HSVColor(120, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), new ColorManager.HSVColor(180, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), new ColorManager.HSVColor(240, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), new ColorManager.HSVColor(300, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), new ColorManager.HSVColor(360, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(), }; //Calculate positions float percent = 1.0f / 6; float[] thePositions = {0.0f, percent, percent * 2, percent * 3, percent * 4, percent * 5, 1.0f}; //Set blend var theBlend = new ColorBlend(); theBlend.Colors = theColors; theBlend.Positions = thePositions; //Get rectangle var colorRect = new Rectangle(0, (Slider.Height / 2) - 3, Slider.Width - 6, 4); //Make the linear brush and assign the custom blend to it var theBrush = new LinearGradientBrush(colorRect, Color.Red, Color.Red, 0, false); theBrush.InterpolationColors = theBlend; //Draw rectangle g.FillRectangle(theBrush, colorRect); //Draw border and trackbar g.DrawRectangle(Pens.Black, new Rectangle(0, (Slider.Height / 2) - 3, Slider.Width - 6, 4)); DrawThumb(g); }
/// <summary> /// 生成验证码 /// </summary> /// <returns></returns> public static byte[] Generate(Action<string> saveCode) { int width = 35; int height = 16; int len = 4; Bitmap img = new Bitmap(width, height); MemoryStream ms = new MemoryStream(); Graphics g = Graphics.FromImage(img); Rectangle r = new Rectangle(0, 0, img.Width, img.Height); Font font = new Font("Arial", 11, FontStyle.Bold); LinearGradientBrush brush = new LinearGradientBrush(r, Color.Red, Color.Orange, 90); Random random = new Random(); StringBuilder code = new StringBuilder(len); for (int i = 0; i < len; i++) code.Append(random.Next(10)); g.Clear(Color.White); g.DrawString(code.ToString(), font, brush, 0, 0); saveCode(code.ToString()); for (int i = 0; i < 20; i++) { int x = random.Next(img.Width); int y = random.Next(img.Height); img.SetPixel(x, y, Color.FromArgb(random.Next())); } img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); g.Dispose(); ms.Dispose(); img.Dispose(); return ms.ToArray(); }
public override void Draw(Graphics g) { RectangleF rect = rectComponent.TopLeftCorner.CloneAndAdd(0, offSet).MakeRectangleFTill(rectComponent.BottomRightCorner.CloneAndAdd(0, -offSet)); RectangleF upperRect = rectComponent.TopLeftCorner.MakeRectangleFTill(rectComponent.TopLeftCorner.CloneAndAdd(rectComponent.Width, 2 * offSet)); RectangleF lowerRect = rectComponent.BottomRightCorner.CloneAndAdd(-rectComponent.Width, -2 * offSet).MakeRectangleFTill(rectComponent.BottomRightCorner); using (LinearGradientBrush brush = new LinearGradientBrush(rect, ViewFactory.GradStartColor, ViewFactory.GradEndColor, 90.0f)) { g.FillRectangle(brush, rect); g.DrawRectangle(ViewFactory.BorderPen, rect.X, rect.Y, rect.Width, rect.Height); } using (LinearGradientBrush brush = new LinearGradientBrush(upperRect, ViewFactory.GradStartColor, ViewFactory.GradEndColor, 90.0f)) { g.FillEllipse(brush, upperRect); g.DrawEllipse(ViewFactory.BorderPen, upperRect.X, upperRect.Y, upperRect.Width, upperRect.Height); } using (LinearGradientBrush brush = new LinearGradientBrush(lowerRect, ViewFactory.GradStartColor, ViewFactory.GradEndColor, 90.0f)) { g.FillEllipse(brush, lowerRect); g.DrawArc(ViewFactory.BorderPen, lowerRect, 0, 180); } base.Draw(g); }
void paintshit(List<double> datta, int numPoints, double mulX, double mulY, int bw, int bh, Graphics g, LinearGradientBrush grad, Color cbase) { PointF[] points = new PointF[numPoints]; lock (datta) { int s = 0; int samples = datta.Count; for (; s < (points.Length - 2) - samples; s++) { points[s + 1] = new PointF((float)(s * mulX), bh); } int ofs = (points.Length - 2) - samples; s = Math.Max(0, samples - (points.Length - 2)); for (; s < samples; s++) { points[s + ofs + 1] = new PointF((float)((s + ofs) * mulX), (float)(bh - datta[s] * mulY)); } points[0] = new PointF(0f, bh); points[points.Length - 1] = new PointF(bw, bh); } GraphicsPath gp = new GraphicsPath(); gp.AddLines(points); g.FillPath(grad, gp); g.DrawPath(new Pen(cbase, 2f), gp); }
public static void GradientRect(Graphics g, Rectangle bounds, Color a, Color b) { using (LinearGradientBrush br = new LinearGradientBrush(bounds, b, a, -90)) { g.FillRectangle(br, bounds); } }
/// <summary> Method is called whenever this form is resized. </summary> /// <param name="e"></param> /// <remarks> This redraws the background of this form </remarks> protected override void OnResize(EventArgs e) { base.OnResize(e); // Get rid of any current background image if (BackgroundImage != null) { BackgroundImage.Dispose(); BackgroundImage = null; } if (ClientSize.Width > 0) { // Create the items needed to draw the background Bitmap image = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics gr = Graphics.FromImage(image); Rectangle rect = new Rectangle(new Point(0, 0), ClientSize); // Create the brush LinearGradientBrush brush = new LinearGradientBrush(rect, SystemColors.Control, ControlPaint.Dark(SystemColors.Control), LinearGradientMode.Vertical); brush.SetBlendTriangularShape(0.33F); // Create the image gr.FillRectangle(brush, rect); gr.Dispose(); // Set this as the backgroundf BackgroundImage = image; } }
/// <summary> /// 绘制窗体主体部分白色透明层 /// </summary> /// <param name="form"></param> /// <param name="g"></param> public static void DrawFromAlphaMainPart(Form form, Graphics g) { Color[] colors = { Color.FromArgb(5, Color.White), Color.FromArgb(30, Color.White), Color.FromArgb(145, Color.White), Color.FromArgb(150, Color.White), Color.FromArgb(30, Color.White), Color.FromArgb(5, Color.White) }; float[] pos = { 0.0f, 0.04f, 0.10f, 0.90f, 0.97f, 1.0f }; ColorBlend colorBlend = new ColorBlend(6); colorBlend.Colors = colors; colorBlend.Positions = pos; RectangleF destRect = new RectangleF(0, 0, form.Width, form.Height); using (LinearGradientBrush lBrush = new LinearGradientBrush(destRect, colors[0], colors[5], LinearGradientMode.Vertical)) { lBrush.InterpolationColors = colorBlend; g.FillRectangle(lBrush, destRect); } }
/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { // Fill the background. if (ApplicationManager.ApplicationStyle.TabPageCommandBarTopColor == ApplicationManager.ApplicationStyle.TabPageCommandBarBottomColor) using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarTopColor)) e.Graphics.FillRectangle(solidBrush, VirtualClientRectangle); else using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(VirtualClientRectangle, ApplicationManager.ApplicationStyle.TabPageCommandBarTopColor, ApplicationManager.ApplicationStyle.TabPageCommandBarBottomColor, LinearGradientMode.Vertical)) e.Graphics.FillRectangle(linearGradientBrush, VirtualClientRectangle); // Draw the bottom line highlight color. using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarHighlightColor)) e.Graphics.FillRectangle(solidBrush, 0, 0, 1, VirtualHeight-1); // Draw the bottom line lowlight color. using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarLowlightColor)) e.Graphics.FillRectangle(solidBrush, 0, VirtualHeight-2, VirtualWidth, 1); // Draw the bottom line highlight color. using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarHighlightColor)) e.Graphics.FillRectangle(solidBrush, 0, VirtualHeight-1, VirtualWidth, 1); // Call the base class's method so that registered delegates receive the event. base.OnPaint(e); }
/// <summary> /// Creates an action result containing the file contents of a png/image with the captcha chars /// </summary> public static ActionResult CaptchaResult(SessionWrapper session) { var randomText = GenerateRandomText(6); var hash = Utils.GetMd5Hash(randomText + GetSalt(), Encoding.ASCII); session.CaptchaHash = hash; var rnd = new Random(); var fonts = new[] { "Verdana", "Times New Roman" }; float orientationAngle = rnd.Next(0, 359); const int height = 30; const int width = 120; var index0 = rnd.Next(0, fonts.Length); var familyName = fonts[index0]; using (var bmpOut = new Bitmap(width, height)) { var g = Graphics.FromImage(bmpOut); var gradientBrush = new LinearGradientBrush(new Rectangle(0, 0, width, height), Color.White, Color.DarkGray, orientationAngle); g.FillRectangle(gradientBrush, 0, 0, width, height); DrawRandomLines(ref g, width, height); g.DrawString(randomText, new Font(familyName, 18), new SolidBrush(Color.Gray), 0, 2); var ms = new MemoryStream(); bmpOut.Save(ms, ImageFormat.Png); var bmpBytes = ms.GetBuffer(); bmpOut.Dispose(); ms.Close(); return new FileContentResult(bmpBytes, "image/png"); } }
/// <summary> /// The graphics device and clip rectangle are in the parent coordinates. /// </summary> /// <param name="g"></param> /// <param name="clipRectangle"></param> /// <param name="symbol">The symbol to use for drawing.</param> public void Draw(Graphics g, Rectangle clipRectangle, ISymbol symbol) { Color topLeft; Color bottomRight; if (_isSelected) { topLeft = _selectionColor.Darker(.3F); bottomRight = _selectionColor.Lighter(.3F); } else { topLeft = _backColor.Lighter(.3F); bottomRight = _backColor.Darker(.3F); } LinearGradientBrush b = new LinearGradientBrush(_bounds, topLeft, bottomRight, LinearGradientMode.ForwardDiagonal); GraphicsPath gp = new GraphicsPath(); gp.AddRoundedRectangle(Bounds, _roundingRadius); g.FillPath(b, gp); gp.Dispose(); b.Dispose(); Matrix old = g.Transform; Matrix shift = g.Transform; shift.Translate(_bounds.Left + _bounds.Width / 2, _bounds.Top + _bounds.Height / 2); g.Transform = shift; if (symbol != null) { OnDrawSymbol(g, symbol); } g.Transform = old; }
/// <summary> /// Instructs this button to draw itself. /// </summary> /// <param name="g">The graphics surface to draw to.</param> public void Draw(Graphics g) { if (_bounds.Width == 0 || _bounds.Height == 0) return; Pen border = null; // Pen innerBorder = Pens.White; Brush fill = null; if (!_selected && !_highlighted) { border = new Pen(Color.Gray); fill = new LinearGradientBrush(Bounds, BackColor.Lighter(.2f), BackColor.Darker(.2f), 45); } if (!_selected && _highlighted) { border = new Pen(Color.FromArgb(216, 240, 250)); fill = new LinearGradientBrush(Bounds, Color.FromArgb(245, 250, 253), Color.FromArgb(232, 245, 253), LinearGradientMode.Vertical); } if (_selected && !_highlighted) { border = new Pen(Color.FromArgb(153, 222, 253)); fill = new LinearGradientBrush(Bounds, Color.FromArgb(241, 248, 253), Color.FromArgb(213, 239, 252), LinearGradientMode.Vertical); } if (_selected && _highlighted) { border = new Pen(Color.FromArgb(182, 230, 251)); fill = new LinearGradientBrush(Bounds, Color.FromArgb(232, 246, 253), Color.FromArgb(196, 232, 250), LinearGradientMode.Vertical); } GraphicsPath gp = new GraphicsPath(); gp.AddRoundedRectangle(Bounds, 2); if (fill != null) g.FillPath(fill, gp); if (border != null) g.DrawPath(border, gp); gp.Dispose(); if (fill != null) fill.Dispose(); }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { Color start = _startColor; Color end = _endColor; ToolStrip toolStrip = e.ToolStrip; Graphics g = e.Graphics; int boundsHeight = e.AffectedBounds.Height; int height = (boundsHeight + _lines - 1) / _lines; int width = e.AffectedBounds.Width; int stripeHeight = height - 1; Rectangle stripeRect; using (Brush b = new LinearGradientBrush(new Rectangle(0, 0, width, stripeHeight), start, end, LinearGradientMode.Horizontal)) { for (int idx = 0; idx < _lines; idx++) { stripeRect = new Rectangle(0, height * idx + 1, width, stripeHeight); g.FillRectangle(b, stripeRect); } } if (this.DrawEndLine) { using (Brush solidBrush = new SolidBrush(Color.FromArgb(177, 177, 177))) { g.FillRectangle(solidBrush, new Rectangle(0, boundsHeight - 1, width, 1)); } } }
private void CreateCheckCodeImage(string checkCode) { checkCode = checkCode ?? string.Empty; if (!string.IsNullOrEmpty(checkCode)) { Bitmap image = new Bitmap(80, 15); Graphics graphics = Graphics.FromImage(image); try { Random random = new Random(); graphics.Clear(Color.White); Font font = new Font("Fixedsys", 12f, FontStyle.Bold); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.FromArgb(random.Next(0xff), random.Next(0xff), random.Next(0xff)), Color.FromArgb(random.Next(200), random.Next(200), random.Next(200)), 1.2f, true); graphics.DrawString(checkCode, font, brush, (float)-3f, (float)-2f); for (int i = 0; i < 80; i++) { int x = random.Next(image.Width); int y = random.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(random.Next())); } MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Gif); base.Response.ClearContent(); base.Response.ContentType = "image/Gif"; base.Response.BinaryWrite(stream.ToArray()); } finally { graphics.Dispose(); image.Dispose(); } } }
private void DrawContent(Graphics graphics, Rectangle rect) { using (LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0), new Point(rect.Width, rect.Height), Color.White, Color.LightGreen)) { graphics.FillRectangle(brush, rect); } if (!string.IsNullOrEmpty(_title)) { using (Font titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, FontStyle.Bold)) { graphics.DrawString(_title, titleFont, Brushes.Black, rect); // Update the rect to position the body text SizeF titleSize = graphics.MeasureString(_title, titleFont, rect.Width); int titleHeight = (int)titleSize.Height + 1; rect.Offset(0, titleHeight); rect.Height -= titleHeight; } } if (!string.IsNullOrEmpty(_description)) { using (Font bodyFont = new Font(FontFamily.GenericSerif, 12.0f, FontStyle.Regular)) { rect.Inflate(-2, 0); graphics.DrawString(_description, bodyFont, Brushes.Black, rect); } } }
public static System.Drawing.Brush GetBrush(this Brush brush, Rect frame) { var cb = brush as SolidBrush; if (cb != null) { return new System.Drawing.SolidBrush (cb.Color.GetColor ()); } var lgb = brush as LinearGradientBrush; if (lgb != null) { var s = lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * frame.Size; var e = lgb.Absolute ? lgb.End : frame.Position + lgb.End * frame.Size; var b = new System.Drawing.Drawing2D.LinearGradientBrush (GetPointF (s), GetPointF (e), System.Drawing.Color.Black, System.Drawing.Color.Black); var bb = BuildBlend (lgb.Stops); if (bb != null) { b.InterpolationColors = bb; } return b; } var rgb = brush as RadialGradientBrush; if (rgb != null) { var r = rgb.GetAbsoluteRadius (frame); var c = rgb.GetAbsoluteCenter (frame); var path = new GraphicsPath (); path.AddEllipse (GetRectangleF (new Rect (c - r, 2 * r))); var b = new PathGradientBrush (path); var bb = BuildBlend (rgb.Stops, true); if (bb != null) { b.InterpolationColors = bb; } return b; } throw new NotImplementedException ("Brush " + brush); }
/// <summary> /// �ؼ��ػ�. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); LinearGradientBrush brush = new LinearGradientBrush(CaptionRectangle, m_StartColor, m_EndColor, 90.0f); e.Graphics.FillRectangle(brush, CaptionRectangle); }
protected override void OnPaintWidget(PaintEventArgs e) { using (LinearGradientBrush background = new LinearGradientBrush(DisplayRectangle, Color.FromArgb(178, 30, 30, 30), Color.FromArgb(178, 96, 96, 96), LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(background, DisplayRectangle); } // time Font timeFont = new Font(SystemFonts.MenuFont.FontFamily, 60, FontStyle.Bold, GraphicsUnit.Pixel); string time = DateTime.Now.ToString("HH:mm"); SizeF timeSize = e.Graphics.MeasureString(time, timeFont); int x = (int) ((Width - timeSize.Width)/2); int y = 0; e.Graphics.DrawString(time, timeFont, Brushes.DarkGray, x + 1, y + 1); e.Graphics.DrawString(time, timeFont, Brushes.White, x, y); // date Font dateFont = new Font(SystemFonts.MenuFont.FontFamily, 23, FontStyle.Bold, GraphicsUnit.Pixel); string date = DateTime.Now.ToString("dddd, dd. MMMM yyyy"); SizeF dateSize = e.Graphics.MeasureString(date, dateFont); x = (int) ((Width - dateSize.Width)/2); y += 70; e.Graphics.DrawString(date, dateFont, Brushes.DarkGray, x + 1, y + 1); e.Graphics.DrawString(date, dateFont, Brushes.White, x, y); }
public static beCaptcha crear() { beCaptcha obeCaptcha = new beCaptcha(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { sb.Append(generarCaracterAzar()); } Bitmap bmp = new Bitmap(200, 80); Graphics grafico = Graphics.FromImage(bmp); Rectangle rect = new Rectangle(0, 0, 200, 80); LinearGradientBrush deg = new LinearGradientBrush (rect, Color.Aqua, Color.Blue, LinearGradientMode.BackwardDiagonal); grafico.FillRectangle(deg, rect); grafico.DrawString(sb.ToString(), new Font("Arial", 35), Brushes.White, 0, 10); Point punto1; Point punto2; Random oAzar = new Random(); for (int i = 0; i < 5; i++) { punto1 = new Point(oAzar.Next(200), oAzar.Next(80)); punto2 = new Point(oAzar.Next(200), oAzar.Next(80)); grafico.DrawLine(new Pen(Brushes.Yellow, 2), punto1, punto2); } obeCaptcha.Codigo = sb.ToString(); using (MemoryStream ms = new MemoryStream()) { bmp.Save(ms, ImageFormat.Jpeg); obeCaptcha.Imagen = ms.ToArray(); } return (obeCaptcha); }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); if (e.Index != -1) { if ((e.State & DrawItemState.Selected) != DrawItemState.None) { LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, this.MouseColor, this.mouseGradientColor, LinearGradientMode.Vertical); Rectangle rect = new Rectangle(1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2); e.Graphics.FillRectangle(brush, rect); Pen pen = new Pen(this.ItemBorderColor); e.Graphics.DrawRectangle(pen, rect); } else { SolidBrush brush2 = new SolidBrush(this.DropBackColor); e.Graphics.FillRectangle(brush2, e.Bounds); } string s = base.Items[e.Index].ToString(); Color color = ((e.State & DrawItemState.Selected) != DrawItemState.None) ? this.ItemHoverForeColor : this.ForeColor; StringFormat format = new StringFormat { LineAlignment = StringAlignment.Center }; e.Graphics.DrawString(s, this.Font, new SolidBrush(color), e.Bounds, format); } }
public static void FillRectangle(Graphics g, Rectangle rect, Color backgroundColor, Color borderColor, Color frontColor, String text, StringFormat format, Point textPosition) { Rectangle rectA = new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1); // Enable anti-alias g.SmoothingMode = SmoothingMode.AntiAlias; // Draw content filled rectangle if (rectA.Width >= 1.5f) { Brush sectionBrush = new System.Drawing.Drawing2D.LinearGradientBrush(rectA, backgroundColor, BlendColors(backgroundColor, Color.Black, 0.4f), System.Drawing.Drawing2D.LinearGradientMode.Vertical); g.FillRectangle(sectionBrush, rectA); sectionBrush.Dispose(); } // Draw text if (text != null) { Region oldClip = g.Clip; RectangleF clipRect = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height); clipRect.Intersect(g.ClipBounds); g.SetClip(clipRect); Font font = new Font("Tahoma", 8, FontStyle.Regular); Brush brush = new SolidBrush(frontColor); g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawString(text, font, brush, textPosition, format); g.SmoothingMode = SmoothingMode.None; font.Dispose(); brush.Dispose(); format.Dispose(); g.Clip = oldClip; } // Draw border Pen borderPen = new Pen(Color.FromArgb(192, borderColor.R, borderColor.G, borderColor.B)); g.DrawRectangle(borderPen, rectA); borderPen.Dispose(); g.SmoothingMode = SmoothingMode.None; }
public static System.Drawing.Bitmap GenImage(int width, int height, System.Drawing.Drawing2D.LinearGradientBrush brush, byte alpha) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graph = Graphics.FromImage(bmp); graph.FillRectangle(brush, new Rectangle(0, 0, width, height)); BitmapData bitmapData = new BitmapData(); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); bmp.LockBits( rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb, bitmapData); unsafe { uint *pixels = (uint *)bitmapData.Scan0; if (pixels == null) { return(null); } uint col = 0; int stride = bitmapData.Stride >> 2; for (uint row = 0; row < bitmapData.Height; ++row) { uint total_row_len = (uint)(row * stride); for (col = 0; col < bitmapData.Width; ++col) { uint index = total_row_len + col; uint color = pixels[index] & 0xFFFFFF; pixels[index] = color; } } } bmp.UnlockBits(bitmapData); return(bmp); }
/// <summary> /// Event: Overrides the onpaint event and paints the form /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { this.OnPaintBackground(e); for (int i = 0; i < this.TabCount; i++) { this.PaintBorder(e); Rectangle tabArea = this.GetTabRect(i); Pen borderPen = new Pen(SystemColors.ControlDark); System.Drawing.Brush buttonBrush = new System.Drawing.Drawing2D.LinearGradientBrush( tabArea, SystemColors.ControlDark, SystemColors.ControlLight, LinearGradientMode.Vertical); GraphicsPath path = new GraphicsPath(); path.Reset(); if (i == this.SelectedIndex) { buttonBrush = new System.Drawing.Drawing2D.LinearGradientBrush( tabArea, SystemColors.ControlLight, SystemColors.ControlLightLight, LinearGradientMode.Vertical); borderPen = new Pen(new SolidBrush(Color.Gray)); this.PaintTab(i, path, true); e.Graphics.FillPath(buttonBrush, path); e.Graphics.DrawPath(borderPen, path); } else { this.PaintTab(i, path, false); e.Graphics.FillPath(buttonBrush, path); e.Graphics.DrawPath(borderPen, path); } borderPen.Dispose(); buttonBrush.Dispose(); this.PaintText(e, i); this.PaintTabImage(e.Graphics, i); } }
/// <summary> /// RENDERING LAYOUT /// </summary> /// <param name="canvas"></param> /// <param name="graphics"></param> /// <param name="channel"></param> protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, System.Drawing.Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects) { button = GH_Capsule.CreateTextCapsule(ButtonBounds, ButtonBounds, GH_Palette.Transparent, "", new int[] { 0, 0, 0, 5 }, 0); button.Render(graphics, Selected, Owner.Locked, false); button.Render(graphics, Color.FromArgb(255, 50, 100, 150)); button2 = GH_Capsule.CreateTextCapsule(ButtonBounds2, ButtonBounds2, GH_Palette.Transparent, "", new int[] { 0, 0, 5, 0 }, 0); button2.Render(graphics, Selected, Owner.Locked, false); button2.Render(graphics, Color.FromArgb(255, 230, 200, 10)); if (Globals.OpenThisShell[thisIndex2] == true) { System.Drawing.Drawing2D.LinearGradientBrush lgb = new System.Drawing.Drawing2D.LinearGradientBrush( rec0.Location, pythonRect.Location, System.Drawing.Color.FromArgb(255, 0, 200, 0), // Opaque red System.Drawing.Color.FromArgb(255, 0, 200, 0)); // Opaque blue); System.Drawing.Pen p = new System.Drawing.Pen(Color.Black, 1); p.DashCap = System.Drawing.Drawing2D.DashCap.Round; p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; Rectangle r5 = rec0; r5.Inflate(5, 5); // graphics.DrawLine(p, rec0.Location, pythonRect.Location); graphics.DrawPath(p, RoundedRect(r5, 3)); //graphics.DrawRectangle(p, rec0); } StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; Brush gg = new SolidBrush(Color.FromArgb(255, 50, 100, 150)); graphics.DrawString(Owner.NickName, GH_FontServer.Standard, gg, new PointF(rec0.Left, rec0.Bottom + 5)); button.Dispose(); } }
private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Brush b, Single StartAngle, Single SweepAngle) { PagePie pl = new PagePie(); pl.StartAngle = StartAngle; pl.SweepAngle = SweepAngle; StyleInfo SI = new StyleInfo(); pl.X = X + recX * SCALEFACTOR; pl.Y = Y + recY * SCALEFACTOR; pl.W = recWidth * SCALEFACTOR; pl.H = recHeight * SCALEFACTOR; switch (b.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b; SI.Color = theBrush.Color; SI.BackgroundColor = theBrush.Color; break; case "LinearGradientBrush": System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b; SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight; SI.BackgroundColor = linBrush.LinearColors[0]; SI.BackgroundGradientEndColor = linBrush.LinearColors[1]; break; case "HatchBrush": System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b; SI.BackgroundColor = hatBrush.BackgroundColor; SI.Color = hatBrush.ForegroundColor; SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle); break; default: break; } pl.SI = SI; items.Add(pl); }
private void CreateCheckCodeImage(string checchCode) { if (checchCode == null || checchCode.Trim() == string.Empty) { return; } System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checchCode.Length * 12.5)), 22); Graphics g = Graphics.FromImage(image); try { Random random = new Random(); g.Clear(Color.White); for (int i = 0; i < 25; i++) { int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawLine(new Pen(Color.GreenYellow), x1, y1, x2, y2); } Font font = new System.Drawing.Font("Verdana", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true); g.DrawString(checchCode, font, brush, 2, 2); for (int i = 0; i < 2; i++) { int x = random.Next(image.Width); int y = random.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(random.Next())); } g.DrawRectangle(new Pen(Color.Red), 0, 0, image.Width - 1, image.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.ClearContent(); Response.ContentType = "image/Gif"; Response.BinaryWrite(ms.ToArray()); } finally { g.Dispose(); image.Dispose(); } }
private void DrawWithAddorner(IntPtr hdc, User32.RECT iconBounds, Boolean isGhosted, Int32 width, Int32 height, IntPtr hThumbnail, Int32 addornerType) { Int32 width2, height2; if (addornerType == 2) { var addorner = new Bitmap(width + 7, height + 7, PixelFormat.Format32bppPArgb); var gb = new LinearGradientBrush(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, this._CurrentSize), Color.WhiteSmoke, Color.WhiteSmoke); addorner = Gdi32.RoundCorners(addorner, 0, gb, new Pen(Color.LightGray)); var hAddorner = addorner.GetHbitmap(); Gdi32.ConvertPixelByPixel(hAddorner, out width2, out height2); Gdi32.NativeDraw(hdc, hAddorner, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width2) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height2 - (height2 <= width2 && height2 < this._CurrentSize ? 4 : height2 == width2 ? 4 : 1)), width2, height2, isGhosted); Gdi32.DeleteObject(hAddorner); addorner.Dispose(); Gdi32.NativeDraw(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width2) / 2 + 3, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height2) - (height2 <= width2 && height2 < this._CurrentSize ? 1 : height2 == width2 ? 1 : (-2)), width, height, isGhosted); } else if (addornerType == 3) { var isWide = (height / (Double)width) < 0.6; var hAddorner = isWide ? this._VideAddornerWide.GetHBitmap(this._CurrentSize, true, true) : this._VideAddorner.GetHBitmap(this._CurrentSize, true, true); Gdi32.ConvertPixelByPixel(hAddorner, out width2, out height2); if (isWide) { Gdi32.NativeDrawCrop(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2 + (Int32)(this._CurrentSize * 0.12), iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2 + (Int32)(this._CurrentSize * 0.07 / 2), (Int32)(this._CurrentSize * 0.12), (Int32)(this._CurrentSize * 0.03 / 2), width - (Int32)(this._CurrentSize * 0.13 * 2), height - (Int32)(this._CurrentSize * 0.03), isGhosted); var left = iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2; var top = iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2; Gdi32.NativeDraw(hdc, hAddorner, left, top, width2, height2, width2, height + (Int32)(this._CurrentSize * 0.07) - (Int32)(this._CurrentSize * 0.04), isGhosted); } else { Gdi32.NativeDrawCrop(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2 + (Int32)(this._CurrentSize * 0.12), iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2 + (Int32)(this._CurrentSize * 0.07 / 2), (Int32)(this._CurrentSize * 0.12), (Int32)(this._CurrentSize * 0.03 / 2), width - (Int32)(this._CurrentSize * 0.13 * 1.9), height - (Int32)(this._CurrentSize * 0.07), isGhosted); Gdi32.NativeDraw(hdc, hAddorner, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width2, height2, width2, height + (Int32)(this._CurrentSize * 0.06) - (Int32)(this._CurrentSize * 0.07), isGhosted); } Gdi32.DeleteObject(hAddorner); } }
public static System.Drawing.Brush GetBrush(this Brush brush, Rect frame) { var cb = brush as SolidBrush; if (cb != null) { return(new System.Drawing.SolidBrush(cb.Color.GetColor())); } var lgb = brush as LinearGradientBrush; if (lgb != null) { var s = lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * frame.Size; var e = lgb.Absolute ? lgb.End : frame.Position + lgb.End * frame.Size; var b = new System.Drawing.Drawing2D.LinearGradientBrush(GetPointF(s), GetPointF(e), System.Drawing.Color.Black, System.Drawing.Color.Black); var bb = BuildBlend(lgb.Stops); if (bb != null) { b.InterpolationColors = bb; } return(b); } var rgb = brush as RadialGradientBrush; if (rgb != null) { var r = rgb.GetAbsoluteRadius(frame); var c = rgb.GetAbsoluteCenter(frame); var path = new GraphicsPath(); path.AddEllipse(GetRectangleF(new Rect(c - r, 2 * r))); var b = new PathGradientBrush(path); var bb = BuildBlend(rgb.Stops, true); if (bb != null) { b.InterpolationColors = bb; } return(b); } throw new NotImplementedException("Brush " + brush); }
/// <summary> /// Draws the aqua pill /// </summary> /// <param name="graphicsDevice">Graphics device</param> /// <param name="drawRectF">Float rectangle</param> /// <param name="drawColor">A Color</param> /// <param name="orientation">Enumeration orientation</param> public static void DrawAquaPill(Graphics graphicsDevice, RectangleF drawRectF, Color drawColor, Orientation orientation) { Color color1; Color color2; Color color3; Color color4; Color color5; System.Drawing.Drawing2D.LinearGradientBrush gradientBrush; System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(); color1 = ColorHelper.OpacityMix(Color.White, ColorHelper.SoftLightMix(drawColor, Color.Black, 100), 40); color2 = ColorHelper.OpacityMix(Color.White, ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColor(64, 64, 64), 100), 20); color3 = ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColor(128, 128, 128), 100); color4 = ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColor(192, 192, 192), 100); color5 = ColorHelper.OverlayMix(ColorHelper.SoftLightMix(drawColor, Color.White, 100), Color.White, 75); colorBlend.Colors = new Color[] { color1, color2, color3, color4, color5 }; colorBlend.Positions = new float[] { 0, 0.25f, 0.5f, 0.75f, 1 }; if (orientation == Orientation.Horizontal) { gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top - 1), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height + 1), color1, color5); } else { gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left - 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width + 1, (int)drawRectF.Top), color1, color5); } gradientBrush.InterpolationColors = colorBlend; FillPill(gradientBrush, drawRectF, graphicsDevice); color2 = Color.White; colorBlend.Colors = new Color[] { color2, color3, color4, color5 }; colorBlend.Positions = new float[] { 0, 0.5f, 0.75f, 1 }; if (orientation == Orientation.Horizontal) { gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left + 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + 1, (int)drawRectF.Top + (int)drawRectF.Height - 1), color2, color5); } else { gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top + 1), new Point((int)drawRectF.Left + (int)drawRectF.Width - 1, (int)drawRectF.Top + 1), color2, color5); } gradientBrush.InterpolationColors = colorBlend; FillPill(gradientBrush, RectangleF.Inflate(drawRectF, -3, -3), graphicsDevice); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent) { pevent.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; pevent.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; pevent.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Brush brush1 = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle, base.BackColor, _BackColor2, BackFillMode); pevent.Graphics.FillRectangle(brush1, ClientRectangle); brush1.Dispose(); System.Drawing.Pen pen = new System.Drawing.Pen(BorderColor, 2.0F); System.Drawing.Rectangle rectangle3 = ClientRectangle; System.Drawing.Rectangle rectangle4 = ClientRectangle; System.Drawing.Rectangle rectangle5 = ClientRectangle; System.Drawing.Rectangle rectangle1 = new System.Drawing.Rectangle(rectangle3.Location, new System.Drawing.Size(rectangle4.Width, rectangle5.Height)); pevent.Graphics.DrawRectangle(pen, rectangle1); pen.Dispose(); System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat(); stringFormat.Alignment = System.Drawing.StringAlignment.Center; stringFormat.LineAlignment = System.Drawing.StringAlignment.Center; stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide; stringFormat.FormatFlags = System.Drawing.StringFormatFlags.LineLimit; stringFormat.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; System.Drawing.Brush brush2 = new System.Drawing.SolidBrush(base.ForeColor); pevent.Graphics.DrawString(Text, Font, brush2, ClientRectangle, stringFormat); if (Image != null) { System.Drawing.Image image = Image; System.Drawing.Rectangle rectangle6 = ClientRectangle; System.Drawing.Point point1 = rectangle6.Location; System.Drawing.Rectangle rectangle7 = ClientRectangle; int i1 = point1.X + 5; if (this.ImageAlign == ContentAlignment.MiddleCenter) { i1 = point1.X + ((rectangle7.Width - image.Width) / 2); } System.Drawing.Rectangle rectangle8 = ClientRectangle; System.Drawing.Point point2 = rectangle8.Location; System.Drawing.Rectangle rectangle9 = ClientRectangle; int i2 = point2.Y + ((rectangle9.Height - image.Height) / 2); System.Drawing.Rectangle rectangle2 = new System.Drawing.Rectangle(i1, i2, image.Width, image.Height); pevent.Graphics.DrawImage(image, rectangle2); } }
private void PaintTabBackground(System.Drawing.Graphics graph, int index, System.Drawing.Drawing2D.GraphicsPath path) { Rectangle rect = this.GetTabRect(index); System.Drawing.Brush buttonBrush = new System.Drawing.Drawing2D.LinearGradientBrush( rect, SystemColors.ControlLightLight, SystemColors.ControlLight, LinearGradientMode.Vertical); if (index == this.SelectedIndex) { buttonBrush = new System.Drawing.SolidBrush(SystemColors.ControlLightLight); } graph.FillPath(buttonBrush, path); buttonBrush.Dispose(); }
protected override void DrawItemBackground(TreeListItemRenderEventArgs e) { if (e.DrawState == DrawState.Selected) { var rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 1); using (var l = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.FromArgb(60, 144, 218, 144), Color.FromArgb(60, 0, 100, 0), 90)) { e.Graphics.FillPath(l, CreateRoundedRectanglePath(rect, 4)); } e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawPath(Pens.Green, CreateRoundedRectanglePath(rect, 4)); return; } base.DrawItemBackground(e); }
private void CreateCheckCodeImage(string checkCode) { if (checkCode == null || checkCode.Trim() == string.Empty) { return; } System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)Math.Ceiling(Convert.ToDouble(checkCode.Length * 15)), 22); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); try { Random random = new Random(); graphics.Clear(System.Drawing.Color.White); for (int i = 0; i < 25; i++) { int x = random.Next(bitmap.Width); int x2 = random.Next(bitmap.Width); int y = random.Next(bitmap.Height); int y2 = random.Next(bitmap.Height); graphics.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Silver), x, y, x2, y2); } System.Drawing.Font font = new System.Drawing.Font("Arial", 12f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 1.2f, true); graphics.DrawString(checkCode, font, brush, 2f, 2f); for (int j = 0; j < 100; j++) { int x3 = random.Next(bitmap.Width); int y3 = random.Next(bitmap.Height); bitmap.SetPixel(x3, y3, System.Drawing.Color.FromArgb(random.Next())); } graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Silver), 0, 0, bitmap.Width - 1, bitmap.Height - 1); MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif); base.Response.ClearContent(); base.Response.ContentType = "image/Gif"; base.Response.BinaryWrite(memoryStream.ToArray()); } finally { graphics.Dispose(); bitmap.Dispose(); } }
public static string CreateTextPic3(string text, System.Drawing.Color color1, System.Drawing.Color color2, string fontname, float fontsize, float width, float height, FontStyle fs, string savePath, string idTag = "") { if (string.IsNullOrEmpty(text.Trim())) { return(""); } System.Drawing.Bitmap image = new System.Drawing.Bitmap(width.ToInt(), height.ToInt()); Graphics g = Graphics.FromImage(image); try { //清空图片背景色 g.Clear(System.Drawing.Color.Transparent);//背景色正常为黑色 Font font = new System.Drawing.Font(fontname, fontsize, fs); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), color1, color2, 1.2f, true); g.DrawString(text, font, brush, 2, 2); IOHelper.FolderCheck(Config.GetMapPath(savePath)); Random rnd = new Random(Config.GetRandomSeed()); string FilePath = savePath + idTag + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + rnd.Next(1000, 9999) + ".png"; //System.IO.MemoryStream ms = new System.IO.MemoryStream(); //image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //HttpContext.Current.Response.ClearContent(); //HttpContext.Current.Response.ContentType = "image/Jpeg"; //HttpContext.Current.Response.BinaryWrite(ms.ToArray()); image.Save(Config.GetMapPath(FilePath), System.Drawing.Imaging.ImageFormat.Png); return(FilePath); } catch (Exception ex) { Config.Err(ex); return(""); } finally { g.Dispose(); image.Dispose(); } }
//public void SetBlendTriangularShape(double focus); //public void SetBlendTriangularShape(double focus, double scale); //public void SetSigmaBellShape(double focus); //public void SetSigmaBellShape(double focus, double scale); #if GDI //TODO: Change from LinearGradient to RadialGradient internal override System.Drawing.Brush RealizeGdiBrush() { //if (dirty) //{ // if (brush == null) // brush = new SolidBrush(color.ToGdiColor()); // else // { // brush.Color = color.ToGdiColor(); // } // dirty = false; //} #if not_implemented // TODO: use dirty to optimize code GdiLinearGradientBrush brush; try { Lock.EnterGdiPlus(); if (_useRect) { brush = new GdiLinearGradientBrush(_rect.ToRectangleF(), _color1.ToGdiColor(), _color2.ToGdiColor(), (LinearGradientMode)_linearGradientMode); } else { brush = new GdiLinearGradientBrush( _point1.ToPointF(), _point2.ToPointF(), _color1.ToGdiColor(), _color2.ToGdiColor()); } if (!_matrix.IsIdentity) { brush.Transform = _matrix.ToGdiMatrix(); } //brush.WrapMode = WrapMode.Clamp; } finally { Lock.ExitGdiPlus(); } return(brush); #else return(null); #endif }
/// <summary> /// 生成验证码图片 /// </summary> /// <param name="validate"></param> public void CreateValidateImage(string validateCode, int width, int height) { //如果验证码字符串长度等于零,直接返回,不再生成图片 if (validateCode.Length == 0) { return; } Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); Font f24 = new Font("黑体", 24, FontStyle.Bold); Brush br = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, width, height), Color.DarkGreen, Color.Red, 1.2f, true); //文字下面的干扰线 for (int i = 0; i < 50; i++) { int x1 = rd.Next(i, width - 2); int y1 = rd.Next(1, height - 2); int x2 = x1 + 2; int y2 = y1 + 2; g.DrawLine(Pens.SkyBlue, x1, y1, x2, y2); } g.DrawString(validateCode, f24, br, 2, 0); //文字上面的干扰线 for (int i = 0; i < 50; i++) { int x1 = rd.Next(i, width - 2); int y1 = rd.Next(1, height - 2); int x2 = x1 - 2; int y2 = y1 - 2; g.DrawLine(Pens.Aqua, x1, y1, x2, y2); } g.DrawRectangle(Pens.Black, 0, 0, width - 2, height - 2); //验证码写到cookie,不需要长久保存 HttpCookie vCodeCookie = new HttpCookie("vCode", validateCode); context.Response.Cookies.Add(vCodeCookie); this.context.Response.ContentType = "image/jpeg"; bmp.Save(this.context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); }
/// <summary> /// 回发验证码图片 [斜体粗体渐变颜色] /// </summary> /// <param name="context"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="chkStr"></param> public static void ResponseImage(System.Web.HttpContext context, int width, int height, string chkStr) { Bitmap newMap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); Graphics g = Graphics.FromImage(newMap); g.Clear(Color.White); Random random = new Random(); int i; for (i = 0; i < 25; i++) { int x1 = random.Next(newMap.Width); int x2 = random.Next(newMap.Width); int y1 = random.Next(newMap.Height); int y2 = random.Next(newMap.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } FontStyle sf = FontStyle.Italic | FontStyle.Bold; Font textFont = new Font("GB2312", 12, sf, GraphicsUnit.Point); Rectangle r = new Rectangle(0, 0, width, height + 4); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(r, Color.Blue, Color.DarkRed, 1.5F, true); g.DrawRectangle(new Pen(Color.Silver), 0, 0, newMap.Width - 1, newMap.Height - 1); StringFormat strFrm = new StringFormat(); //strFrm.Alignment = StringAlignment.Center; strFrm.LineAlignment = StringAlignment.Center; strFrm.FormatFlags = StringFormatFlags.LineLimit; strFrm.FormatFlags = StringFormatFlags.NoWrap; SizeF sizef = g.MeasureString(chkStr, textFont); r.X = (r.Width - Convert.ToInt32(sizef.Width)) / 2; r.Height -= 4; g.DrawString(chkStr, textFont, brush, r, strFrm); newMap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); newMap.Dispose(); }
/// <summary> /// 根据验证码字符生成验证码图片 /// </summary> /// <param name="checkCode"></param> /// <returns></returns> public static Image CreateCheckCodeImage() { string checkCode = GenerateCheckCode(); HttpContext.Current.Session["uuid"] = checkCode; //将字符串保存到Session中,以便需要时进行验证 System.Drawing.Bitmap image = new System.Drawing.Bitmap(70, 22); Graphics g = System.Drawing.Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); //清空图片背景色 g.Clear(System.Drawing.Color.White); // 画图片的背景噪音线 int i; for (i = 0; i < 25; i++) { int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold)); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2F, true); g.DrawString(checkCode, font, brush, 2, 2); //画图片的前景噪音点 g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); } finally { g.Dispose(); } return(image); }
private void colorDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; int rectangleLocationX = e.CellBounds.X + 3; int rectangleLocationY = e.CellBounds.Y + 3; int rectangleWidth = e.CellBounds.Width - 6; int rectangleHeight = e.CellBounds.Height - 6; float emptySpotGradientAngle = (float)70.0; System.Drawing.Rectangle spotRectangle = new System.Drawing.Rectangle(rectangleLocationX, rectangleLocationY, rectangleWidth, rectangleHeight); System.Drawing.Rectangle gradientBigRectangle = new System.Drawing.Rectangle(rectangleLocationX, rectangleLocationY, rectangleWidth, rectangleHeight * 2); System.Drawing.Rectangle gradientBiggerRectangle = new System.Drawing.Rectangle(rectangleLocationX - 10, rectangleLocationY - 10, rectangleWidth + 20, rectangleHeight * 3); System.Drawing.Drawing2D.LinearGradientBrush normalPenBrush = new LinearGradientBrush(gradientBiggerRectangle, Color.Silver, Color.Black, emptySpotGradientAngle, true); System.Drawing.Pen normalPen = new System.Drawing.Pen(normalPenBrush, 3.0f); System.Drawing.Drawing2D.LinearGradientBrush br; float filledSpotGradientAngle = (float)270.0; Color c = colorArray[e.ColumnIndex]; br = new System.Drawing.Drawing2D.LinearGradientBrush(gradientBigRectangle, Color.Black, c, filledSpotGradientAngle, false); e.Graphics.FillRectangle(br, spotRectangle); // hilite ellipse = based on http://www3.telus.net/ryanfransen/article_glassspheres.html int r3w = Convert.ToInt16(spotRectangle.Width); int r3h = Convert.ToInt16(spotRectangle.Height * 0.4); Rectangle r3 = new Rectangle( new Point(spotRectangle.Location.X, spotRectangle.Location.Y + 1), new Size(r3w, r3h)); LinearGradientBrush br2 = new LinearGradientBrush(r3, Color.White, Color.Transparent, 90); br2.WrapMode = WrapMode.TileFlipX; e.Graphics.FillRectangle(br2, r3); br2.Dispose(); e.Graphics.DrawRectangle(normalPen, spotRectangle); e.PaintContent(e.ClipBounds); e.Handled = true; br.Dispose(); normalPen.Dispose(); normalPenBrush.Dispose(); }
/// <summary> /// 重绘Column、Row /// </summary> /// <param name="e"></param> protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { // //如果是Column // if(e.RowIndex == -1) { // drawColumnAndRow(e); // e.Handled = true; // //如果是Rowheader // } else if(e.ColumnIndex < 0 && e.RowIndex>=0) { // drawColumnAndRow(e); // _RowHeadWidth = e.CellBounds.Width; // e.Handled = true; //} StringFormat StrFormat = new StringFormat(); Rectangle Rect = new Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1); System.Drawing.Drawing2D.LinearGradientBrush LinearGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, System.Drawing.Drawing2D.LinearGradientMode.Vertical); //try //{ if (e.RowIndex == -1 || e.ColumnIndex == -1) { e.Graphics.FillRectangle(LinearGradientBrush, Rect); e.Graphics.DrawRectangle(new Pen(mGridColor), Rect); e.PaintContent(e.CellBounds); e.Handled = true; } //} //catch (Exception ex) //{ //} //finally //{ // Rect = null; // StrFormat.Dispose(); // if (LinearGradientBrush != null) // { // LinearGradientBrush.Dispose(); // } //} }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { if (ThemeConfig.EffectiveTheme != PdnTheme.Aero) { base.OnRenderToolStripBackground(e); } else if (e.ToolStrip is ToolStripDropDown) { e.Graphics.FillRectangle(this.penBrushCache.GetSolidBrush(this.AeroColorTheme.MenuItemBackFillColor), e.AffectedBounds); } else { if (e.ToolStrip is StatusStrip) { Rectangle affectedBounds = e.AffectedBounds; int num = affectedBounds.Y + 1; affectedBounds.Y = num; num = affectedBounds.Height - 1; affectedBounds.Height = num; using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.AffectedBounds, this.AeroColorTheme.StatusBackFillGradTopColor, this.AeroColorTheme.StatusBackFillGradBottomColor, LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(brush, e.AffectedBounds); return; } } if (e.ToolStrip is ToolStripEx) { Rectangle rect = e.AffectedBounds; e.Graphics.TryFillRectangle(this.penBrushCache.GetSolidBrush(this.AeroColorTheme.ToolBarBackFillGradMidColor), rect); if (this.DrawToolStripExBackgroundTopSeparatorLine) { e.Graphics.DrawLine(this.penBrushCache.GetPen(this.AeroColorTheme.ToolBarOutlineColor), e.AffectedBounds.Left, e.AffectedBounds.Top, e.AffectedBounds.Right, e.AffectedBounds.Top); } } else { base.OnRenderToolStripBackground(e); } } }
/// <summary> /// Draws the actual scale on the gauge /// </summary> /// <param name="g"></param> private void DrawScale(Graphics g) { Rectangle scalerect = rcentre; scalerect.Inflate(-2, -2); Color realstart = Color.FromArgb(m_alphaForGaugeColors, m_startColor); Color realend = Color.FromArgb(m_alphaForGaugeColors, m_endColor); scalerect = new Rectangle(scalerect.X + 1, scalerect.Y + 1, scalerect.Width, scalerect.Height); System.Drawing.Drawing2D.LinearGradientBrush gb = new System.Drawing.Drawing2D.LinearGradientBrush(rcentre, realstart, realend, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); // percentage calulation float range = m_maxValue - m_minValue; float percentage = (m_value - m_minValue) / range; //float percentage = (m_value) / (m_maxValue - m_minValue); if (percentage > 1) { percentage = 1; } float width = scalerect.Width * percentage; Rectangle fillrect = new Rectangle(scalerect.X - 1, scalerect.Y - 1, (int)width, scalerect.Height + 1); g.FillRectangle(gb, fillrect); // draw peak & hold? if (m_MaxPeakHoldValue > float.MinValue && m_peakholdOpaque > 0) { Color peakholdcolor = Color.FromArgb(m_peakholdOpaque, Color.Red); percentage = (m_MaxPeakHoldValue - m_minValue) / range; if (percentage > 1) { percentage = 1; } width = scalerect.Width * percentage; g.DrawLine(new Pen(peakholdcolor, 3), new Point(scalerect.X - 1 + (int)width, scalerect.Y - 1), new Point(scalerect.X - 1 + (int)width, scalerect.Y + scalerect.Height)); } gb.Dispose(); }
public byte[] CreateCheckCodeImage(string checkCode) { byte[] bytes; System.Drawing.Bitmap img = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 14.5)), 23); Graphics g = Graphics.FromImage(img); try { g.Clear(Color.White); for (int i = 0; i < 25; i++) { int x1 = ran.Next(img.Width); int x2 = ran.Next(img.Width); int y1 = ran.Next(img.Height); int y2 = ran.Next(img.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.DarkRed, 1.2f, true); g.DrawString(checkCode, font, brush, 2, 2); for (int j = 0; j < 100; j++) { int x = ran.Next(img.Width); int y = ran.Next(img.Height); img.SetPixel(x, y, Color.FromArgb(ran.Next())); } g.DrawRectangle(new Pen(Color.Black), 0, 0, img.Width - 1, img.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); bytes = ms.ToArray(); } finally { g.Dispose(); img.Dispose(); } return(bytes); }
public override void DrawTab(Graphics gr, Rectangle borderrect, int index, bool selected, Color color1, Color color2, Color coloroutline, TabAlignment alignment) { System.Diagnostics.Debug.Assert(alignment == TabAlignment.Top); int additional = 0; // extra depth for fill if (selected) { additional = 1; borderrect.Height += borderrect.Y; // this one uses any height to get it bigger borderrect.Y = 0; } int radius = 10; int xfar = borderrect.Right - 1; int yfar = borderrect.Bottom - 1; GraphicsPath border = new GraphicsPath(); border.AddLine(borderrect.X, yfar, borderrect.X, borderrect.Y); border.AddArc(xfar - radius * 2, borderrect.Y, radius * 2, radius * 2, 270, 90); border.AddLine(xfar, yfar, xfar, yfar); GraphicsPath fill = new GraphicsPath(); fill.AddLine(borderrect.X + 1, yfar + 1 + additional, borderrect.X + 1, borderrect.Y); fill.AddArc(xfar - radius * 2, borderrect.Y, radius * 2, radius * 2, 270, 90); fill.AddLine(xfar, yfar + 1 + additional, xfar, yfar + 1 + additional); gr.SmoothingMode = SmoothingMode.Default; using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, color1, color2, 90)) gr.FillPath(b, fill); gr.SmoothingMode = SmoothingMode.AntiAlias; using (Pen p = new Pen(coloroutline, 1.0F)) gr.DrawPath(p, border); }
//边缘模糊 public static RenderTargetBitmap SetEdgeBlur(Bitmap bitmap, int blurRange, IList <DetectedFace> faceList) { System.Drawing.Color backColor = GetBackColor(faceList); Bitmap b = bitmap; Graphics g = Graphics.FromImage(b); Rectangle rect = new System.Drawing.Rectangle(b.Width - blurRange, 0, blurRange, b.Height); rect = new System.Drawing.Rectangle(0, 0, b.Width, blurRange); using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect, backColor, System.Drawing.Color.FromArgb(0, backColor), LinearGradientMode.Vertical)) { g.FillRectangle(brush, rect); } rect = new Rectangle(0, 0, blurRange, b.Height); using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect, backColor, System.Drawing.Color.FromArgb(0, backColor), LinearGradientMode.Horizontal)) { g.FillRectangle(brush, rect); } rect = new System.Drawing.Rectangle(b.Width - blurRange, 0, blurRange, b.Height); using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect, System.Drawing.Color.FromArgb(0, backColor), backColor, LinearGradientMode.Horizontal)) { g.FillRectangle(brush, rect); } rect = new System.Drawing.Rectangle(0, b.Height - blurRange, b.Width, blurRange); using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect, System.Drawing.Color.FromArgb(0, backColor), backColor, LinearGradientMode.Vertical)) { g.FillRectangle(brush, rect); } return(Redraw(faceList, BitmapToBitmapImage(b))); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Rectangle aRect; System.Drawing.Drawing2D.GraphicsPath oPath; LinearGradientBrush _splitBrush; Rectangle _splitRect = new Rectangle(0, this.Height - 10, this.Width, 10); aRect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); oPath = Ai.Renderer.Drawing.roundedRectangle(aRect, 2, 2, 2, 2); oPath.CloseFigure(); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.FillPath(new SolidBrush(Color.FromArgb(250, 250, 250)), oPath); if (_showSizingGrip != SizingGripMode.None) { _splitBrush = new System.Drawing.Drawing2D.LinearGradientBrush(_splitRect, Color.Black, Color.White, System.Drawing.Drawing2D.LinearGradientMode.Vertical); _splitBrush.InterpolationColors = Ai.Renderer.Drawing.SizingGripBlend; e.Graphics.FillRectangle(_splitBrush, _splitRect); if (_showSizingGrip == SizingGripMode.BottomRight) { Ai.Renderer.Drawing.drawGrip(e.Graphics, this.Width - 12, this.Height - 12); } else { Ai.Renderer.Drawing.drawVGrip(e.Graphics, _splitRect); } e.Graphics.DrawLine(Ai.Renderer.Drawing.GripBorderPen, 0, _splitRect.Y, this.Width, _splitRect.Y); _splitBrush.Dispose(); } e.Graphics.DrawPath(new Pen(Color.FromArgb(134, 134, 134)), oPath); oPath.Dispose(); aRect = new Rectangle(0, 0, this.Width, this.Height); oPath = Ai.Renderer.Drawing.roundedRectangle(aRect, 2, 2, 2, 2); this.Region = new Region(oPath); oPath.Dispose(); }
private void DoInstructions(PointF[] Ps, Brush b) { PagePolygon pl = new PagePolygon(); //pl.X = X * SCALEFACTOR; //pl.Y = Y * SCALEFACTOR; pl.Points = Ps; StyleInfo SI = new StyleInfo(); switch (b.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b; SI.Color = theBrush.Color; SI.BackgroundColor = theBrush.Color; break; case "LinearGradientBrush": System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b; SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight; SI.BackgroundColor = linBrush.LinearColors[0]; SI.BackgroundGradientEndColor = linBrush.LinearColors[1]; break; case "HatchBrush": System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b; SI.BackgroundColor = hatBrush.BackgroundColor; SI.Color = hatBrush.ForegroundColor; SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle); break; default: break; } pl.SI = SI; items.Add(pl); }
/// <summary> /// Paints the background for the control. If the TransparencyMode is true, /// no background is painted. /// </summary> /// <param name="pevent"></param> protected override void OnPaintBackground(PaintEventArgs pevent) { if (TransparentMode) { return; } // Getting the graphics object Graphics g = pevent.Graphics; // Creating the rectangle for the gradient Rectangle rBackground = new Rectangle(0, 0, this.Width, this.Height); // Creating the lineargradient System.Drawing.Drawing2D.LinearGradientBrush bBackground = new System.Drawing.Drawing2D.LinearGradientBrush(rBackground, _Color1, _Color2, _ColorAngle); // Draw the gradient onto the form g.FillRectangle(bBackground, rBackground); // Disposing of the resources held by the brush bBackground.Dispose(); }
protected override void OnDrawItem(DrawItemEventArgs e) { using (var _textBrush = new SolidBrush(this.ForeColor)) { TabPage _tabPage = this.TabPages[e.Index]; Rectangle _tabBounds = this.GetTabRect(e.Index); if (e.State != DrawItemState.Selected) { e.DrawBackground(); } else { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.White, Color.LightGray, 90f)) { e.Graphics.FillRectangle(brush, e.Bounds); } } StringFormat _stringFlags = new StringFormat(); _stringFlags.Alignment = StringAlignment.Center; _stringFlags.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(_tabPage.Text, this.Font, _textBrush, _tabBounds, new StringFormat(_stringFlags)); } }
/// <summary> /// 生成验证码图片 /// </summary> private byte[] CreateImage(string str_ValidateCode) { int int_ImageWidth = str_ValidateCode.Length * 22; Random newRandom = new Random(); Bitmap theBitmap = new Bitmap(int_ImageWidth + 6, 38); Graphics theGraphics = Graphics.FromImage(theBitmap); theGraphics.Clear(ColorTranslator.FromHtml("#ffffff")); drawLine(theGraphics, theBitmap, newRandom); theGraphics.DrawRectangle(new Pen(Color.LightGray, 1), 0, 0, theBitmap.Width - 1, theBitmap.Height - 1); for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++) { Matrix X = new Matrix(); X.Shear((float)newRandom.Next(0, 300) / 1000 - 0.25f, (float)newRandom.Next(0, 100) / 1000 - 0.05f); theGraphics.Transform = X; string str_char = str_ValidateCode.Substring(int_index, 1); // System.Drawing.Drawing2D.LinearGradientBrush newBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, theBitmap.Width, theBitmap.Height), ColorTranslator.get, Color.DarkRed, 1.2f, true); System.Drawing.Drawing2D.LinearGradientBrush newBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, theBitmap.Width, theBitmap.Height), ColorTranslator.FromHtml("#FF0505"), ColorTranslator.FromHtml("#FF0505"), 1.2f, true); Point thePos = new Point(int_index * 21 + 1 + newRandom.Next(3), 1 + newRandom.Next(13)); Font theFont = new Font(Fonts[newRandom.Next(Fonts.Length - 1)], newRandom.Next(14, 18), FontStyle.Bold); theGraphics.DrawString(str_char, theFont, newBrush, thePos); } MemoryStream ms = new MemoryStream(); theBitmap.Save(ms, ImageFormat.Png); drawPoint(theBitmap, newRandom); theGraphics.Dispose(); theBitmap.Dispose(); return(ms.ToArray()); }