public static void RenderEllipseGlass(Graphics g, Rectangle ownerRect, GlassPosition position, float positionFactor, Color glassColor, int alphaCenter, int alphaSurround) { if (!(positionFactor > 0 && positionFactor < 1)) throw new ArgumentException("positionFactor must be between 0 and 1, but not include 0 and 1. ", "positionFactor"); ownerRect.Height--; ownerRect.Width--; if (ownerRect.Width < 1 || ownerRect.Height < 1) return; using (GraphicsPath gp = new GraphicsPath()) { gp.AddEllipse(ownerRect); using (PathGradientBrush pb = new PathGradientBrush(gp)) { pb.CenterPoint = GetEllipseGlassCenterPoint(ownerRect, position, positionFactor); pb.CenterColor = Color.FromArgb(alphaCenter, glassColor); pb.SurroundColors = new Color[] { Color.FromArgb(alphaSurround, glassColor) }; using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias)) { g.FillPath(pb, gp); } } } }
protected virtual void DrawButton(Graphics g, Rectangle buttonRect) { this.BuildGraphicsPath(buttonRect); PathGradientBrush brush = new PathGradientBrush(this.bpath); brush.SurroundColors = new Color[] { this.buttonColor }; buttonRect.Offset(this.buttonPressOffset, this.buttonPressOffset); if (this.bevelHeight > 0) { buttonRect.Inflate(1, 1); brush.CenterPoint = new PointF((float) ((buttonRect.X + (buttonRect.Width / 8)) + this.buttonPressOffset), (float) ((buttonRect.Y + (buttonRect.Height / 8)) + this.buttonPressOffset)); brush.CenterColor = this.cColor; this.FillShape(g, brush, buttonRect); this.ShrinkShape(ref g, ref buttonRect, this.bevelHeight); } if (this.bevelDepth > 0) { this.DrawInnerBevel(g, buttonRect, this.bevelDepth, this.buttonColor); this.ShrinkShape(ref g, ref buttonRect, this.bevelDepth); } brush.CenterColor = this.buttonColor; if (this.dome) { brush.CenterColor = this.cColor; brush.CenterPoint = new PointF((float) ((buttonRect.X + (buttonRect.Width / 8)) + this.buttonPressOffset), (float) ((buttonRect.Y + (buttonRect.Height / 8)) + this.buttonPressOffset)); } this.FillShape(g, brush, buttonRect); if (this.gotFocus) { this.DrawFocus(g, buttonRect); } }
protected override void OnPaintBackground(PaintEventArgs pevent) { base.OnPaintBackground(pevent); pevent.Graphics.Clear(Color.FromArgb(0)); foreach (TabPage tab in this.TabPages) { Rectangle tabRect = GetTabRect(this.TabPages.IndexOf(tab)); using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; SizeF textSize = pevent.Graphics.MeasureString(tab.Text, this.Font); RectangleF rc = new RectangleF(tabRect.Left + ((tabRect.Width / 2) - (textSize.Width / 2)), tabRect.Top + tabRect.Height / 2 - textSize.Height / 2, textSize.Width, textSize.Height); rc.Inflate(4, 5); GraphicsPath path = new GraphicsPath(); path.AddRectangle(rc); using (PathGradientBrush brush = new PathGradientBrush(path)) { brush.CenterColor = Color.FromArgb(192, tab == this.SelectedTab ? Color.Red : Color.Black); brush.SurroundColors = new Color[] { Color.Black }; pevent.Graphics.FillRectangle(brush,rc); } var tc = new SolidBrush(Color.FromArgb(tab.ForeColor.A, tab.ForeColor.R, tab.ForeColor.G, tab.ForeColor.B)); pevent.Graphics.DrawString(tab.Text, this.Font, tc, rc, sf); } } }
public void Paint(PaintEventArgs e) { Graphics g = e.Graphics; rect = new Rectangle(x, y, width, height); Point[] pt = { new Point(rect.X,rect.Y), new Point(rect.X+rect.Width,rect.Y), new Point(rect.X+rect.Width,rect.Y+rect.Height), new Point(rect.X,rect.Y+rect.Height) }; PathGradientBrush pth = new PathGradientBrush(pt); pth.SurroundColors = new Color[] { Color.FromArgb(10,R,G,B) }; g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X + rect.Width / 10, rect.Y), new Point(rect.X + rect.Width / 10, rect.Y + rect.Height)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X, rect.Y), new Point(rect.X + (rect.Width / 10), rect.Y)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X + (rect.Width - rect.Width / 10), rect.Y), new Point(rect.X + rect.Width, rect.Y)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X + (rect.Width - rect.Width / 10), rect.Y), new Point(rect.X + (rect.Width - rect.Width / 10), rect.Y + rect.Height)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X + rect.Width / 3, rect.Y + 3), new Point(rect.X + rect.Width / 3, rect.Y + rect.Height)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X + (rect.Width / 3) * 2, rect.Y + 3), new Point(rect.X + (rect.Width / 3) * 2, rect.Y + rect.Height)); g.DrawLine(new Pen(Color.FromArgb(255, R, G, B), 2), new Point(rect.X + rect.Width, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height)); pth.CenterColor = Color.FromArgb(A, R, G, B); g.FillRectangle(pth, rect); }
protected override void OnPaint(PaintEventArgs e) { using (SolidBrush b = new SolidBrush(BackColor)) { e.Graphics.FillRectangle(b, ClientRectangle); } RectangleF wheelrect = WheelRectangle; Util.DrawFrame(e.Graphics, wheelrect, 6, m_frameColor); wheelrect = ColorWheelRectangle; PointF center = Util.Center(wheelrect); e.Graphics.SmoothingMode = SmoothingMode.HighSpeed; if (m_brush == null) { m_brush = new PathGradientBrush(m_path.ToArray(), WrapMode.Clamp); m_brush.CenterPoint = center; m_brush.CenterColor = Color.White; m_brush.SurroundColors = m_colors.ToArray(); } e.Graphics.FillPie(m_brush, Util.Rect(wheelrect), 0, 360); DrawColorSelector(e.Graphics); if (Focused) { RectangleF r = WheelRectangle; r.Inflate(-2,-2); ControlPaint.DrawFocusRectangle(e.Graphics, Util.Rect(r)); } }
/// <summary> /// Draws a breakpoint icon in the margin. /// </summary> /// <param name="g">The <see cref="Graphics"/> context.</param> /// <param name="rectangle">The bounding rectangle.</param> /// <param name="isEnabled"><c>true</c> if enabled..</param> /// <param name="willBeHit"><c>true</c> if it will be hit.</param> public static void DrawBreakpoint(Graphics g, Rectangle rectangle, bool isEnabled, bool willBeHit) { int diameter = Math.Min(rectangle.Width - 4, rectangle.Height); Rectangle rect = new Rectangle(2, rectangle.Y + (rectangle.Height - diameter) / 2, diameter, diameter); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(rect); using (PathGradientBrush pthGrBrush = new PathGradientBrush(path)) { pthGrBrush.CenterPoint = new PointF(rect.Left + rect.Width / 3, rect.Top + rect.Height / 3); pthGrBrush.CenterColor = Color.MistyRose; Color[] colors = { willBeHit ? Color.Firebrick : Color.Olive }; pthGrBrush.SurroundColors = colors; if (isEnabled) { g.FillEllipse(pthGrBrush, rect); } else { g.FillEllipse(SystemBrushes.Control, rect); using (Pen pen = new Pen(pthGrBrush)) { g.DrawEllipse(pen, new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2)); } } } } }
public static void PaintVignette(Graphics g, Rectangle bounds) { Rectangle ellipsebounds = bounds; ellipsebounds.Offset(-ellipsebounds.X, -ellipsebounds.Y); int x = ellipsebounds.Width - (int)Math.Round(.70712 * ellipsebounds.Width); int y = ellipsebounds.Height - (int)Math.Round(.70712 * ellipsebounds.Height); ellipsebounds.Inflate(x, y); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(ellipsebounds); using (PathGradientBrush brush = new PathGradientBrush(path)) { brush.WrapMode = WrapMode.Tile; brush.CenterColor = Color.FromArgb(0, 0, 0, 0); brush.SurroundColors = new Color[] { Color.FromArgb(255, 0, 0, 0) }; Blend blend = new Blend(); blend.Positions = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F }; blend.Factors = new float[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f }; brush.Blend = blend; Region oldClip = g.Clip; g.Clip = new Region(bounds); g.FillRectangle(brush, ellipsebounds); g.Clip = oldClip; } } }
protected override void RenderFrameByCenter(PaintEventArgs e, Rectangle r) { Graphics g = e.Graphics; using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(GaugeFrame.Bounds); using (PathGradientBrush br = new PathGradientBrush(path)) { br.CenterPoint = GaugeFrame.Center; br.CenterColor = GaugeFrame.FrameColor.Start; br.SurroundColors = new Color[] { GaugeFrame.FrameColor.End }; br.SetSigmaBellShape(GaugeFrame.FrameSigmaFocus, GaugeFrame.FrameSigmaScale); g.FillRectangle(br, GaugeFrame.Bounds); } path.AddRectangle(r); using (PathGradientBrush br = new PathGradientBrush(path)) { br.CenterPoint = GaugeFrame.Center; br.CenterColor = GaugeFrame.FrameColor.End; br.SurroundColors = new Color[] { GaugeFrame.FrameColor.Start }; g.FillRectangle(br, r); } } RenderFrameBorder(g, GaugeFrame.Bounds); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics G = e.Graphics; LinearGradientBrush linearGradientBrush1 = new LinearGradientBrush(//创建线性渐变画刷 new Point(0, 0),new Point(20, 20), //渐变起始点和终止点 Color.Yellow,Color.Blue); //渐变起始颜色和终止颜色 G.FillRectangle(linearGradientBrush1, new Rectangle(0, 0, 150, 150));//绘制矩形 LinearGradientBrush linearGradientBrush2 = new LinearGradientBrush(//创建线性渐变画刷 new Rectangle(0, 0, 20, 20), //渐变所在矩形 Color.Yellow, Color.Blue, 60f); //渐变起始颜色、终止颜色以及渐变方向 linearGradientBrush2.WrapMode = WrapMode.TileFlipXY; G.FillRectangle(linearGradientBrush2, new Rectangle(150, 0, 150, 150));//绘制矩形 GraphicsPath graphicsPath1 = new GraphicsPath(); //创建绘制路径 graphicsPath1.AddArc(new Rectangle(0, 150, 100, 100), 90, 180);//向路径中添加半左圆弧 graphicsPath1.AddArc(new Rectangle(150, 150, 100, 100), 270, 180);//向路径中添加半右圆弧 graphicsPath1.CloseFigure(); //闭合路径 PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath1);//创建路径渐变画刷 pathGradientBrush.CenterColor = Color.Yellow; //指定画刷中心颜色 pathGradientBrush.SurroundColors = new Color[] { Color.Blue };//指定画刷周边颜色 pathGradientBrush.CenterPoint = new PointF(125, 200); //指定画刷中心点坐标 G.SmoothingMode = SmoothingMode.AntiAlias; //消锯齿 G.FillPath(pathGradientBrush, graphicsPath1); //利用画刷填充路径 G.DrawPath(new Pen(Color.Lime, 3f), graphicsPath1); //绘制闭合路径曲线 linearGradientBrush1.Dispose(); linearGradientBrush2.Dispose(); graphicsPath1.Dispose(); pathGradientBrush.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle rect = ClientRectangle; if (Dock == DockStyle.Left || Dock == DockStyle.Right) { using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(rect); using (PathGradientBrush brush = new PathGradientBrush(path) { CenterColor = Color.FromArgb(0xFF, 204, 206, 219), SurroundColors = new[] { SystemColors.Control } }) { e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y, Measures.SplitterSize / 3, rect.Height); } } } else { if (Dock == DockStyle.Top || Dock == DockStyle.Bottom) { using (SolidBrush brush = new SolidBrush(Color.FromArgb(0xFF, 204, 206, 219))) { e.Graphics.FillRectangle(brush, rect.X, rect.Y, rect.Width, Measures.SplitterSize); } } } }
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); }
private Color[] CreateGradientPalette() { Bitmap b = new Bitmap(100, 1); var g = Graphics.FromImage(b); Point[] points = { new Point(0, 0), new Point(50, 0), new Point(100, 0), new Point(100, 1) }; Color[] colors = { Color.Red, Color.Yellow, Color.Green }; //GraphicsPath path = new GraphicsPath(); //path.AddLines(points); // Use the path to construct a path gradient brush. PathGradientBrush br = new PathGradientBrush(points); br.SurroundColors = colors; // var br = new LinearGradientBrush(new Point(0, 0), new Point(100, 0), Color.Red, Color.Green); g.FillRectangle(br, 0, 0, 100, 1); Color[] palette = new Color[b.Size.Width]; for (int i = 0; i < palette.Length; i++) { palette[i] = b.GetPixel(i, 0); } b.Dispose(); return palette; }
private void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { // Создаем траекторию GraphicsPath path = new GraphicsPath(); Rectangle rect = new Rectangle(20, 20, 150, 150); path.AddRectangle(rect); // Создаем градиентную кисть PathGradientBrush pgBrush = new PathGradientBrush(path.PathPoints); // Уснинавливаем цвета кисти pgBrush.CenterColor = Color.Red; pgBrush.SurroundColors = new Color[] { Color.Blue }; // Создаем объект Matrix Matrix X = new Matrix(); // Translate X.Translate(30.0f, 10.0f, MatrixOrder.Append); // Rotate X.Rotate(10.0f, MatrixOrder.Append); // Scale X.Scale(1.2f, 1.0f, MatrixOrder.Append); // Shear X.Shear(.2f, 0.03f, MatrixOrder.Prepend); // Применяем преобразование к траектории и кисти path.Transform(X); pgBrush.Transform = X; // Выполняем визуализацию g.FillPath(pgBrush, path); } }
protected override void DrawSlider( PaintEventArgs e ) { float fSizeToDraw = m_SliderRectangle.Width * (Value - VisibleRangeMin) / (VisibleRangeMax - VisibleRangeMin); if ( m_ColorMin.A == 255 && m_ColorMax.A == 255 ) e.Graphics.FillRectangle( m_BackgroundBrush, m_SliderRectangle.X + fSizeToDraw, m_SliderRectangle.Y, m_SliderRectangle.Width - fSizeToDraw, m_SliderRectangle.Height ); else { // Draw a nice checker box background System.Drawing.Drawing2D.HatchBrush Checker = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, Color.Gray, Color.DarkGray ); e.Graphics.FillRectangle( Checker, m_SliderRectangle ); Checker.Dispose(); } // Draw a gradient box if ( fSizeToDraw < 1.0f ) return; // Crashes if empty! RectangleF Rect = new RectangleF( m_SliderRectangle.X, m_SliderRectangle.Y, fSizeToDraw, m_SliderRectangle.Height ); System.Drawing.Drawing2D.GraphicsPath Path = new System.Drawing.Drawing2D.GraphicsPath(); Path.AddRectangle( Rect ); System.Drawing.Drawing2D.PathGradientBrush Gradient = new System.Drawing.Drawing2D.PathGradientBrush( Path ); Gradient.SurroundColors = new Color[] { m_ColorMin, m_ColorMax, m_ColorMax, m_ColorMin }; Gradient.CenterPoint = new PointF( 0.5f * (Rect.Left + Rect.Right), .5f * (Rect.Bottom + Rect.Top) ); Gradient.CenterColor = Color.FromArgb( (m_ColorMin.A + m_ColorMax.A) / 2, (m_ColorMin.R + m_ColorMax.R) / 2, (m_ColorMin.G + m_ColorMax.G) / 2, (m_ColorMin.B + m_ColorMax.B) / 2 ); e.Graphics.FillRectangle( Gradient, Rect ); Gradient.Dispose(); Path.Dispose(); }
public static Bitmap BothAlpha(Bitmap p_Bitmap, bool p_CentralTransparent, bool p_Crossdirection) { Bitmap image = new Bitmap(p_Bitmap.Width, p_Bitmap.Height); Graphics graphics = Graphics.FromImage(image); graphics.DrawImage(p_Bitmap, new Rectangle(0, 0, p_Bitmap.Width, p_Bitmap.Height)); graphics.Dispose(); Bitmap bitmap2 = new Bitmap(image.Width, image.Height); Graphics graphics2 = Graphics.FromImage(bitmap2); System.Drawing.Point point = new System.Drawing.Point(0, 0); System.Drawing.Point point2 = new System.Drawing.Point(bitmap2.Width, 0); System.Drawing.Point point3 = new System.Drawing.Point(bitmap2.Width, bitmap2.Height / 2); System.Drawing.Point point4 = new System.Drawing.Point(0, bitmap2.Height / 2); if (p_Crossdirection) { point = new System.Drawing.Point(0, 0); point2 = new System.Drawing.Point(bitmap2.Width / 2, 0); point3 = new System.Drawing.Point(bitmap2.Width / 2, bitmap2.Height); point4 = new System.Drawing.Point(0, bitmap2.Height); } System.Drawing.Point[] points = new System.Drawing.Point[] { point, point2, point3, point4 }; PathGradientBrush brush = new PathGradientBrush(points, WrapMode.TileFlipY) { CenterPoint = new PointF(0f, 0f), FocusScales = new PointF((float) (bitmap2.Width / 2), 0f), CenterColor = Color.FromArgb(0, 0xff, 0xff, 0xff) }; brush.SurroundColors = new Color[] { Color.FromArgb(0xff, 0xff, 0xff, 0xff) }; if (p_Crossdirection) { brush.FocusScales = new PointF(0f, (float) bitmap2.Height); brush.WrapMode = WrapMode.TileFlipX; } if (p_CentralTransparent) { brush.CenterColor = Color.FromArgb(0xff, 0xff, 0xff, 0xff); brush.SurroundColors = new Color[] { Color.FromArgb(0, 0xff, 0xff, 0xff) }; } graphics2.FillRectangle(brush, new Rectangle(0, 0, bitmap2.Width, bitmap2.Height)); graphics2.Dispose(); BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.ReadOnly, bitmap2.PixelFormat); byte[] destination = new byte[bitmapdata.Stride * bitmapdata.Height]; Marshal.Copy(bitmapdata.Scan0, destination, 0, destination.Length); bitmap2.UnlockBits(bitmapdata); BitmapData data2 = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat); byte[] buffer2 = new byte[data2.Stride * data2.Height]; Marshal.Copy(data2.Scan0, buffer2, 0, buffer2.Length); int index = 0; for (int i = 0; i != data2.Height; i++) { index = (i * data2.Stride) + 3; for (int j = 0; j != data2.Width; j++) { buffer2[index] = destination[index]; index += 4; } } Marshal.Copy(buffer2, 0, data2.Scan0, buffer2.Length); image.UnlockBits(data2); return image; }
public static Bitmap BothAlpha(Bitmap p_Bitmap, bool p_CentralTransparent, bool p_Crossdirection) { Bitmap _SetBitmap = new Bitmap(p_Bitmap.Width, p_Bitmap.Height); Graphics _GraphisSetBitmap = Graphics.FromImage(_SetBitmap); _GraphisSetBitmap.DrawImage(p_Bitmap, new Rectangle(0, 0, p_Bitmap.Width, p_Bitmap.Height)); _GraphisSetBitmap.Dispose(); Bitmap _Bitmap = new Bitmap(_SetBitmap.Width, _SetBitmap.Height); Graphics _Graphcis = Graphics.FromImage(_Bitmap); System.Drawing.Point _Left1 = new System.Drawing.Point(0, 0); System.Drawing.Point _Left2 = new System.Drawing.Point(_Bitmap.Width, 0); System.Drawing.Point _Left3 = new System.Drawing.Point(_Bitmap.Width, _Bitmap.Height / 2); System.Drawing.Point _Left4 = new System.Drawing.Point(0, _Bitmap.Height / 2); if (p_Crossdirection) { _Left1 = new System.Drawing.Point(0, 0); _Left2 = new System.Drawing.Point(_Bitmap.Width / 2, 0); _Left3 = new System.Drawing.Point(_Bitmap.Width / 2, _Bitmap.Height); _Left4 = new System.Drawing.Point(0, _Bitmap.Height); } System.Drawing.Point[] _Point = new System.Drawing.Point[] { _Left1, _Left2, _Left3, _Left4 }; PathGradientBrush _SetBruhs = new PathGradientBrush(_Point, WrapMode.TileFlipY); _SetBruhs.CenterPoint = new PointF(0f, 0f); _SetBruhs.FocusScales = new PointF((float) (_Bitmap.Width / 2), 0f); _SetBruhs.CenterColor = Color.FromArgb(0, 0xff, 0xff, 0xff); _SetBruhs.SurroundColors = new Color[] { Color.FromArgb(0xff, 0xff, 0xff, 0xff) }; if (p_Crossdirection) { _SetBruhs.FocusScales = new PointF(0f, (float) _Bitmap.Height); _SetBruhs.WrapMode = WrapMode.TileFlipX; } if (p_CentralTransparent) { _SetBruhs.CenterColor = Color.FromArgb(0xff, 0xff, 0xff, 0xff); _SetBruhs.SurroundColors = new Color[] { Color.FromArgb(0, 0xff, 0xff, 0xff) }; } _Graphcis.FillRectangle(_SetBruhs, new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height)); _Graphcis.Dispose(); BitmapData _NewData = _Bitmap.LockBits(new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height), ImageLockMode.ReadOnly, _Bitmap.PixelFormat); byte[] _NewBytes = new byte[_NewData.Stride * _NewData.Height]; Marshal.Copy(_NewData.Scan0, _NewBytes, 0, _NewBytes.Length); _Bitmap.UnlockBits(_NewData); BitmapData _SetData = _SetBitmap.LockBits(new Rectangle(0, 0, _SetBitmap.Width, _SetBitmap.Height), ImageLockMode.ReadWrite, _SetBitmap.PixelFormat); byte[] _SetBytes = new byte[_SetData.Stride * _SetData.Height]; Marshal.Copy(_SetData.Scan0, _SetBytes, 0, _SetBytes.Length); int _WriteIndex = 0; for (int i = 0; i != _SetData.Height; i++) { _WriteIndex = (i * _SetData.Stride) + 3; for (int z = 0; z != _SetData.Width; z++) { _SetBytes[_WriteIndex] = _NewBytes[_WriteIndex]; _WriteIndex += 4; } } Marshal.Copy(_SetBytes, 0, _SetData.Scan0, _SetBytes.Length); _SetBitmap.UnlockBits(_SetData); return _SetBitmap; }
private void Form2_Paint(object sender, PaintEventArgs e) { //패스 그래디언트 Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) }; PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile); e.Graphics.FillRectangle(B, ClientRectangle); //패스 그래디언트 끝 //패스변형 GraphicsPath Path = new GraphicsPath(); Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat()); //확장 후 외곽선 그리기 Path.Widen(new Pen(Color.Black, 3)); e.Graphics.DrawPath(Pens.Black, Path); //확장 후 채우기 Path.Widen(new Pen(Color.Blue, 3)); e.Graphics.DrawPath(Pens.Black, Path); //곡선 펴기 Path.Flatten(new Matrix(), 12f); e.Graphics.DrawPath(Pens.Black, Path); //회전 Matrix M = new Matrix(); M.Rotate(-10); Path.Transform(M); e.Graphics.FillPath(Brushes.Blue, Path); //휘기 RectangleF R = Path.GetBounds(); PointF[] arPoint = new PointF[4]; arPoint[0] = new PointF(R.Left, R.Top + 30); arPoint[1] = new PointF(R.Right, R.Top - 10); arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10); arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30); Path.Warp(arPoint, R); e.Graphics.FillPath(Brushes.Blue, Path); //클리핑 //graphicspath path= new graphicspath(); //path.fillmode = fillmode.winding; //path.addellipse(50, 10, 100, 80); //path.addellipse(20, 45, 160, 120); //e.graphics.fillpath(brushes.white, path); //e.graphics.setclip(path); //for (int y = 0; y < bottom; y+= 20) //{ // string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다"; // e.graphics.drawstring(str, font, brushes.blue, 0, y); //} //클리핑 끝 }
/// <summary> /// Adds a vignette effect to the source image based on the given color. /// </summary> /// <param name="source"> /// The <see cref="Image"/> source. /// </param> /// <param name="baseColor"> /// <see cref="Color"/> to base the vignette on. /// </param> /// <param name="rectangle"> /// The rectangle to define the bounds of the area to vignette. If null then the effect is applied /// to the entire image. /// </param> /// <param name="invert"> /// Whether to invert the vignette. /// </param> /// <returns> /// The <see cref="Bitmap"/> with the vignette applied. /// </returns> public static Bitmap Vignette(Image source, Color baseColor, Rectangle? rectangle = null, bool invert = false) { using (Graphics graphics = Graphics.FromImage(source)) { Rectangle bounds = rectangle ?? new Rectangle(0, 0, source.Width, source.Height); Rectangle ellipsebounds = bounds; // Increase the rectangle size by the difference between the rectangle dimensions and sqrt(2)/2 * the rectangle dimensions. // Why sqrt(2)/2? Because the point (sqrt(2)/2, sqrt(2)/2) is the 45 degree angle point on a unit circle. Scaling by the width // and height gives the distance needed to inflate the rectangle to make sure it's fully covered. ellipsebounds.Offset(-ellipsebounds.X, -ellipsebounds.Y); int x = ellipsebounds.Width - (int)Math.Floor(.70712 * ellipsebounds.Width); int y = ellipsebounds.Height - (int)Math.Floor(.70712 * ellipsebounds.Height); ellipsebounds.Inflate(x, y); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(ellipsebounds); using (PathGradientBrush brush = new PathGradientBrush(path)) { // Fill a rectangle with an elliptical gradient brush that goes from transparent to opaque. // This has the effect of painting the far corners with the given color and shade less on the way in to the centre. Color centerColor; Color edgeColor; if (invert) { centerColor = Color.FromArgb(50, baseColor.R, baseColor.G, baseColor.B); edgeColor = Color.FromArgb(0, baseColor.R, baseColor.G, baseColor.B); } else { centerColor = Color.FromArgb(0, baseColor.R, baseColor.G, baseColor.B); edgeColor = Color.FromArgb(255, baseColor.R, baseColor.G, baseColor.B); } brush.WrapMode = WrapMode.Tile; brush.CenterColor = centerColor; brush.SurroundColors = new[] { edgeColor }; Blend blend = new Blend { Positions = new[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F }, Factors = new[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f } }; brush.Blend = blend; Region oldClip = graphics.Clip; graphics.Clip = new Region(bounds); graphics.FillRectangle(brush, ellipsebounds); graphics.Clip = oldClip; } } } return (Bitmap)source; }
public Shape() { GraphicsPath p = new GraphicsPath(); p.AddLine(new Point(0, 0), new Point(100, 100)); //memory error without this, unsure why PathGradientBrush brush = new PathGradientBrush(p); brush.CenterColor = fColor; brush.SurroundColors = eColor; gradient = brush; }
private void ArcGauge_Paint(object sender, PaintEventArgs e) { using (System.Drawing.Drawing2D.GraphicsPath gPath = new System.Drawing.Drawing2D.GraphicsPath()) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.High; //antialias the outer edge using (Pen pen = new Pen(_color1, 2)) e.Graphics.DrawArc(pen, _r, _sAngle, _swAngle); gPath.AddArc(_r, _sAngle, _swAngle); using (System.Drawing.Drawing2D.PathGradientBrush p = new System.Drawing.Drawing2D.PathGradientBrush(gPath)) { p.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; System.Drawing.Drawing2D.Blend b = new System.Drawing.Drawing2D.Blend(); b.Factors = new float[] { 1, 1, 0, 0, 0 }; b.Positions = CalcPositions(_r, _outerWidth); p.Blend = b; p.CenterColor = _color1; p.CenterPoint = new PointF(_r.Width / 2f + _r.X, _r.Height / 2f + _r.Y); //p.SurroundColors = new Color[] { _color2 }; using (Pen pen = new Pen(p, _w)) e.Graphics.DrawArc(pen, _r, _sAngle, _swAngle); } // e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; // e.Graphics.InterpolationMode = InterpolationMode.High; // Pen redPen = new Pen(Color.Red, _arcBrushSize); // redPen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); // Rectangle rect = new Rectangle(_arcBrushSize/2, _arcBrushSize/2, _width - _arcBrushSize, _height); // e.Graphics.DrawArc(redPen, rect, 180, 180); //// Pen bluePen = new Pen(Color.Blue, _arcBrushSize); //// e.Graphics.DrawArc(bluePen, rect, 180, 50); // int textx = _width / 2; // int texty = _height / 2; // String text = "5.7"; // SizeF s = e.Graphics.MeasureString(text, new Font("Arial", 25, FontStyle.Bold)); // e.Graphics.DrawString("5.7", new Font("Arial", 25, FontStyle.Bold), Brushes.Black, textx- s.Width/2, texty - s.Height/2); // bluePen.Dispose(); // redPen.Dispose(); } }
private void panel1_Click(object sender, EventArgs e) { GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(20,20,50,50); PathGradientBrush pgb = new PathGradientBrush(gp); pgb.CenterColor = Color.Red; pgb.SurroundColors = new Color[] {Color.Yellow }; Graphics g = panel1.CreateGraphics(); g.FillEllipse(pgb,20,20,50,50);//creates like a 3d ball. }
public static Brush createFluffyBrush(GraphicsPath gp, float[] blendPositions, float[] blendFactors ) { PathGradientBrush pgb = new PathGradientBrush( gp ); Blend blend = new Blend(); blend.Positions = blendPositions; blend.Factors = blendFactors; pgb.Blend = blend; pgb.CenterColor = Color.White; pgb.SurroundColors = new Color[] { Color.Black }; return pgb; }
/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <param name="image">The current image to process</param> /// <param name="newImage">The new Image to return</param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image TransformImage(ImageFactory factory, Image image, Image newImage) { using (Graphics graphics = Graphics.FromImage(newImage)) { using (ImageAttributes attributes = new ImageAttributes()) { attributes.SetColorMatrix(this.Matrix); Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height); graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); // Add a glow to the image. using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(rectangle); using (PathGradientBrush brush = new PathGradientBrush(path)) { // Fill a rectangle with an elliptical gradient brush that goes from orange to transparent. // This has the effect of painting the far corners transparent and fading in to orange on the // way in to the centre. brush.WrapMode = WrapMode.Tile; brush.CenterColor = Color.FromArgb(70, 255, 153, 102); brush.SurroundColors = new Color[] { Color.FromArgb(0, 0, 0, 0) }; Blend blend = new Blend { Positions = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F }, Factors = new float[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f } }; brush.Blend = blend; Region oldClip = graphics.Clip; graphics.Clip = new Region(rectangle); graphics.FillRectangle(brush, rectangle); graphics.Clip = oldClip; } } } } // Add a vignette to finish the effect. factory.Update(newImage); Vignette vignette = new Vignette(); newImage = (Bitmap)vignette.ProcessImage(factory); // Reassign the image. image.Dispose(); image = newImage; return image; }
//画方块 public void Draw(System.IntPtr winHandle) { Graphics g = Graphics.FromHwnd(winHandle); GraphicsPath gp = new GraphicsPath(); Rectangle rec = new Rectangle(location, size); gp.AddRectangle(rec); Color[] surroundColor = new Color[] { backColor }; PathGradientBrush pb = new PathGradientBrush(gp); pb.CenterColor = foreColor; pb.SurroundColors = surroundColor; g.FillPath(pb, gp); }
private static void DrawBall(Graphics g, Rectangle rect, Color c) { GraphicsPath path = new GraphicsPath (); path.AddEllipse (rect); PathGradientBrush pgbrush = new PathGradientBrush (path); pgbrush.CenterPoint = new Point ((rect.Right - rect.Left) / 3 + rect.Left, (rect.Bottom - rect.Top) / 3 + rect.Top); pgbrush.CenterColor = Color.White; pgbrush.SurroundColors = new Color[] { c }; g.FillEllipse (pgbrush, rect); g.DrawEllipse (new Pen (c), rect); }
private void SetBrushes(){ pen=new Pen(Color.Black,1.6f); hoverBrush=new PathGradientBrush( new Point[] {new Point(0,0),new Point(Width-1,0),new Point(Width-1,Height-1),new Point(0,Height-1)}); hoverBrush.CenterColor=Color.White; surroundColor=Color.FromArgb(249,187,67); hoverBrush.SurroundColors=new Color[] {surroundColor,surroundColor,surroundColor,surroundColor}; Blend blend=new Blend(); float[] myFactors = {0f,.5f,1f,1f,1f,1f}; float[] myPositions = {0f,.2f,.4f,.6f,.8f,1f}; blend.Factors=myFactors; blend.Positions=myPositions; hoverBrush.Blend=blend; }
public IBrush LoadPathsGradientBrush(AGS.API.Color centerColor, AGS.API.PointF centerPoint, IBlend blend, AGS.API.PointF focusScales, AGS.API.Color[] surroundColors, IColorBlend interpolationColors, ITransformMatrix transform, AGS.API.WrapMode wrapMode) { PathGradientBrush g = new PathGradientBrush (new System.Drawing.Point[]{ }); g.Blend = blend.Convert(); g.CenterColor = centerColor.Convert(); g.CenterPoint = centerPoint.Convert(); g.FocusScales = focusScales.Convert(); g.SurroundColors = surroundColors.Convert(); g.InterpolationColors = interpolationColors.Convert(); g.Transform = transform.Convert(); g.WrapMode = wrapMode.Convert(); return new DesktopBrush(g); }
protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); int tmpShadowOffSet = Math.Min(Math.Min(_shadowOffSet, this.Width - 2), this.Height - 2); int tmpSoundCornerRadius = Math.Min(Math.Min(_roundCornerRadius, this.Width - 2), this.Height - 2); if (this.Width > 1 && this.Height > 1) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1); Rectangle rectShadow = new Rectangle(tmpShadowOffSet, tmpShadowOffSet, this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1); GraphicsPath graphPathShadow = GetRoundPath(rectShadow, tmpSoundCornerRadius); GraphicsPath graphPath = GetRoundPath(rect, tmpSoundCornerRadius); if (tmpSoundCornerRadius > 0) { using (PathGradientBrush gBrush = new PathGradientBrush(graphPathShadow)) { gBrush.WrapMode = WrapMode.Clamp; ColorBlend colorBlend = new ColorBlend(3); colorBlend.Colors = new Color[]{Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray)}; colorBlend.Positions = new float[] { 0f, .1f, 1f }; gBrush.InterpolationColors = colorBlend; e.Graphics.FillPath(gBrush, graphPathShadow); } } // Draw backgroup LinearGradientBrush brush = new LinearGradientBrush(rect, this._gradientStartColor, this._gradientEndColor, LinearGradientMode.BackwardDiagonal); e.Graphics.FillPath(brush, graphPath); e.Graphics.DrawPath(new Pen(Color.FromArgb(180, this._borderColor), _borderWidth), graphPath); // Draw Image if (_image != null) { e.Graphics.DrawImageUnscaled(_image, _imageLocation); } } }
public static Bitmap GenerateItemImage(string text, Color color, int width, int height, Font font) { //Debug.WriteLine("GenerateItemImage"); Rectangle rc = new Rectangle(0, 0, width, height); Bitmap itemImage = new Bitmap(rc.Width, rc.Height); /// Create button rc.Inflate(-3, -3); GraphicsPath path1 = GetPath(rc, 10); rc.Inflate(0, 6); LinearGradientBrush br1 = new LinearGradientBrush(rc, color, Color.White, LinearGradientMode.Vertical); rc.Inflate(0, -6); /// Create shadow Rectangle rc2 = rc; rc2.Offset(8, 8); GraphicsPath path2 = GetPath(rc2, 20); PathGradientBrush br2 = new PathGradientBrush(path2); br2.CenterColor = ControlPaint.DarkDark(Color.Silver); br2.SurroundColors = new Color[] { Color.White }; /// Create bubble Rectangle rc3 = rc; rc3.Inflate(-15, -rc.Height / 3); rc3.Y = rc3.Y - 2; //rc3.Height = rc3.Height; GraphicsPath path3 = GetPath(rc3, rc3.Height); LinearGradientBrush br3 = new LinearGradientBrush(rc3, Color.FromArgb(255, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical); itemImage = new Bitmap(width - 2, height); Graphics g = Graphics.FromImage(itemImage); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(br2, path2); g.FillPath(br1, path1); g.FillPath(br3, path3); //SizeF size = g.MeasureString(text, font); //int fontHeight = (int)size.Height + 5; //g.DrawString( // text, // font, // Brushes.Black, // new RectangleF((rc.Width - size.Width) / 2, 2, width, fontHeight)); return itemImage; }
public void Show(IntPtr hwnd) { Graphics surface = Graphics.FromHwnd(hwnd); Rectangle rectangle = new Rectangle(location.X,location.Y,size.Width,size.Height); GraphicsPath path = new GraphicsPath(); path.AddRectangle(rectangle); PathGradientBrush brush = new PathGradientBrush(path); brush.CenterColor = fore; brush.SurroundColors = new Color[] { back }; surface.FillPath(brush,path); }
/// <summary> /// Draws a radial gradient in the label /// </summary> /// <param name="e">paint arguments</param> protected override void OnPaint(PaintEventArgs e) { GraphicsPath path = new GraphicsPath(); path.AddEllipse(this.ClientRectangle); PathGradientBrush brush = new PathGradientBrush(path); brush.CenterPoint = new PointF(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2); brush.CenterColor = this.StartColor; brush.SurroundColors = new Color[] { this.EndColor }; e.Graphics.FillPath(brush, path); brush.Dispose(); path.Dispose(); }
public ColoredRadioButton() { _circle = new Rectangle(2, 5, 7, 7); _glint = new Rectangle(3, 6, 4, 4); _outline = new Pen(new SolidBrush(Color.Black), 1F); GraphicsPath Path = new GraphicsPath(); Path.AddEllipse(_glint); _flareBrush = new PathGradientBrush(Path); _flareBrush.CenterColor = Color.White; _flareBrush.SurroundColors = new Color[] { Color.Transparent }; _flareBrush.FocusScales = new PointF(0.5F, 0.5F); SetStyle(ControlStyles.SupportsTransparentBackColor, true); BackColor = Color.Transparent; }
public sd2.PathGradientBrush GetBrush(RectangleF rect) { var scale = 1f; var bounds = rect; if (Matrix != null) { bounds = Matrix.Inverse().TransformRectangle(bounds); } scale = GradientHelper.GetRadialScale(Center, Radius, GradientOrigin, bounds); if (brush == null || lastScale != scale) { lastScale = scale; var scaledRect = new RectangleF(GradientOrigin - (GradientOrigin - Center + Radius) * scale, GradientOrigin + (Center + Radius - GradientOrigin) * scale); var path = new sd2.GraphicsPath(); path.AddEllipse(scaledRect.ToSD()); brush = new sd2.PathGradientBrush(path); brush.CenterColor = StartColor.ToSD(); brush.CenterPoint = GradientOrigin.ToSD(); brush.WrapMode = wrapMode.ToSD(); brush.SurroundColors = new[] { EndColor.ToSD() }; if (Matrix != null) { brush.MultiplyTransform(Matrix.ToSD()); } if (scale > 1f) { var paths = GradientHelper.GetGradientStops(StartColor.ToSD(), EndColor.ToSD(), scale, wrapMode); brush.InterpolationColors = new sd2.ColorBlend { Positions = paths.Reverse().Select(r => 1f - r.Item1).ToArray(), Colors = paths.Reverse().Select(r => r.Item2).ToArray() }; } } return(brush); }
private void CalculateWheel() { List <PointF> points; List <System.Drawing.Color> colors; points = new List <PointF>(); colors = new List <System.Drawing.Color>(); PointF centerPoint; float radius; if (imageWidth > 16 && imageHeight > 16) { int w = imageWidth; int h = imageHeight; centerPoint = new PointF(w / 2.0f, h / 2.0f); radius = GetRadius(centerPoint); for (double angle = 0; angle < 360; angle += colorStep) { double angleR; PointF location; angleR = angle * (System.Math.PI / 180f); location = GetColorLocation(centerPoint, angleR, radius); points.Add(location); colors.Add(new HslColor(angle + 240, s, l).ToRgbColor()); //colors.Add(ColorFromHSL(angle, s, l)); } } else { return; } Brush result; if (points.Count != 0 && points.Count == colors.Count) { result = new System.Drawing.Drawing2D.PathGradientBrush(points.ToArray(), System.Drawing.Drawing2D.WrapMode.Clamp) { CenterPoint = centerPoint, CenterColor = System.Drawing.Color.White, SurroundColors = colors.ToArray(), }; } else { result = null; } if (result == null) { return; } Image image; int halfSize; halfSize = imageWidth / 2; image = new Bitmap(imageWidth + 2, imageWidth + 2); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image); graphics.FillPie(result, new Rectangle(0, 0, imageWidth, imageHeight), 0, 360); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //using (Pen pen = new Pen(System.Drawing.Color.Black, 2)) //{ // graphics.DrawEllipse(pen, new RectangleF(centerPoint.X - radius, centerPoint.Y - radius, radius * 2, radius * 2)); //} Texture2D texture = new Texture2D(imageWidth + 2, imageHeight + 2, TextureFormat.RGBA32, false); texture.LoadRawTextureData(imageToByteArray(image)); texture.Apply(); colorPickerImage.sprite = Sprite.Create(texture, new Rect(0, 0, imageWidth + 2, imageHeight + 2), Vector2.one); }
protected override void CreateStaticImage() { if (!(this.Width <= 0 || this.Height <= 0)) { this.OnImage = new Bitmap(this.Width, this.Height); this.OffImage = new Bitmap(this.Width, this.Height); Graphics graphic = Graphics.FromImage(this.OnImage); Graphics graphic1 = Graphics.FromImage(this.OffImage); HMIBeveledButtonDisplay.Draw3DBorder(this, graphic, this.m_BorderColor, this.m_BorderWidth); HMIBeveledButtonDisplay.Draw3DBorder(this, graphic1, this.m_BorderColor, this.m_BorderWidth); int width = this.Width - this.m_BorderWidth * 4; if (width <= 0) { width = 1; } int height = this.Height - this.m_BorderWidth * 4; if (height <= 0) { height = 1; } System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(this.m_BorderWidth * 2, this.m_BorderWidth * 2, width, height); System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); graphicsPath.AddRectangle(rectangle); System.Drawing.Drawing2D.PathGradientBrush pathGradientBrush = new System.Drawing.Drawing2D.PathGradientBrush(graphicsPath); if (this.m_BackColorOn != Color.Black) { pathGradientBrush.CenterColor = HMIBeveledButtonDisplay.GetRelativeColor(this.m_BackColorOn, 20); } else { pathGradientBrush.CenterColor = HMIBeveledButtonDisplay.GetRelativeColor(this.BackColor, 20); } Color[] mBackColorOn = new Color[1]; if (this.m_BackColorOn != Color.Black) { mBackColorOn[0] = this.m_BackColorOn; } else { mBackColorOn[0] = HMIBeveledButtonDisplay.GetRelativeColor(this.BackColor, 0.9); } pathGradientBrush.SurroundColors = mBackColorOn; graphic.FillRectangle(pathGradientBrush, rectangle); if (this.m_BackColorOn != Color.Black) { graphic.DrawRectangle(new Pen(new SolidBrush(HMIBeveledButtonDisplay.GetRelativeColor(this.m_BackColorOn, 0.75)), 2.0F), rectangle); } else { graphic.DrawRectangle(new Pen(new SolidBrush(HMIBeveledButtonDisplay.GetRelativeColor(this.m_BorderColor, 0.5)), 2.0F), rectangle); } graphic1.FillRectangle(new SolidBrush(this.BackColor), rectangle); graphic1.DrawRectangle(new Pen(new SolidBrush(HMIBeveledButtonDisplay.GetRelativeColor(this.m_BorderColor, 0.5)), 2.0F), rectangle); this.TextRectangle = new System.Drawing.Rectangle(this.m_BorderWidth * 2 + 1, this.m_BorderWidth * 2 + 1, this.Width - (this.m_BorderWidth * 4 + 2), this.Height - (this.m_BorderWidth * 4 + 2)); byte r = this.ForeColor.R; byte g = this.ForeColor.G; Color foreColor = this.ForeColor; this.TextBrush = new SolidBrush(Color.FromArgb(216, (int)r, (int)g, (int)foreColor.B)); this.Invalidate(); } }
/// <summary> /// 产生验证图片 /// </summary> /// <param name="text">文本</param> /// <param name="font">字体</param> /// <returns></returns> public Image GenerateImage(string text, Font font) { using (StringFormat textFormat = StringFormat.GenericTypographic) { textFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; Size textBlockSize; //创建一个初始图片 在上面测量要生成的文本块的大小 using (Bitmap bmp = new Bitmap(1, 1)) { using (Graphics gh = Graphics.FromImage(bmp)) { //测量文本的所占矩形大小,以便让其自动计算图片大小 textBlockSize = gh.MeasureString(text, font).ToSize(); } } //建立最终输出图片 Image textImage; int w = textBlockSize.Width, h = textBlockSize.Height; textImage = new Bitmap(w, h); try { //建立新的画布 using (Graphics grapTextImage = Graphics.FromImage(textImage)) { Point[] ps = new Point[] { new Point(0, 0), new Point(w, 0), new Point(w, h), new Point(0, h) }; //建立一个路径渐变画笔 using (PathGradientBrush bBackground = new System.Drawing.Drawing2D.PathGradientBrush(ps)) { bBackground.CenterColor = Color.Yellow; //设置渐变过渡色彩 bBackground.SurroundColors = _backgroundSurroundColors; //填充颜色到画布 grapTextImage.FillRectangle(bBackground, 0, 0, w, h); } //建立路径 using (GraphicsPath path = new GraphicsPath()) { //添加文本路径 path.AddString(text, font.FontFamily, 1, font.Size, new PointF(0.0F, 0.0F), textFormat); //建立一个文字路径渐变 using (PathGradientBrush textGradient = new PathGradientBrush(path)) { textGradient.CenterColor = Color.Yellow; textGradient.SurroundColors = _textPathSurroundColors; grapTextImage.FillRectangle(textGradient, 0, 0, w, h); using (LinearGradientBrush lb = new LinearGradientBrush(new Point(0, 0), new Point(w, h), Color.Yellow, Color.FromArgb(239, 239, 0))) { grapTextImage.DrawPath(new Pen(lb), path); } } } grapTextImage.Save(); } } catch { textImage.Dispose(); throw; } return(textImage); } }