// From http://edu.cnzz.cn/show_3281.html public static GraphicsPath CalculateGraphicsPathFromBitmap(Bitmap bitmap, Color colorTransparent) { GraphicsPath graphicsPath = new GraphicsPath(); if (colorTransparent == Color.Empty) colorTransparent = bitmap.GetPixel(0, 0); for(int row = 0; row < bitmap.Height; row ++) { int colOpaquePixel = 0; for(int col = 0; col < bitmap.Width; col ++) { if(bitmap.GetPixel(col, row) != colorTransparent) { colOpaquePixel = col; int colNext = col; for(colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++) if(bitmap.GetPixel(colNext, row) == colorTransparent) break; graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1)); col = colNext; } } } return graphicsPath; }
private void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { GraphicsPath path = new GraphicsPath(); path.AddLine(20, 20, 170, 20); path.AddLine(20, 20, 20, 100); // рисуем новую фигуру path.StartFigure(); path.AddLine(240, 140, 240, 50); path.AddLine(240, 140, 80, 140); path.AddRectangle(new Rectangle(30, 30, 200, 100)); // локальное преобразование траектории //Matrix X = new Matrix(); //X.RotateAt(45, new PointF(60.0f, 100.0f)); //path.Transform(X); // рисуем path Pen redPen = new Pen(Color.Red, 2); g.FillPath(new SolidBrush(Color.Bisque), path); g.DrawPath(redPen, path); } }
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); }
private void pictureBox2_Paint(object sender, PaintEventArgs e) { if (this.pointStart.HasValue && this.pointEnd.HasValue) { var path = new GraphicsPath(FillMode.Alternate); path.AddRectangle(new Rectangle(0, 0, e.ClipRectangle.Width, e.ClipRectangle.Height)); path.AddRectangle(CreateRectangle(this.pointStart.Value, this.pointEnd.Value)); e.Graphics.FillPath(grayBrush, path); } }
/// <summary>Make pause buttons</summary> /// <param name="size"></param> /// <returns></returns> private static GraphicsPath MakePause(Size size) { var pause = new System.Drawing.Drawing2D.GraphicsPath(); int firstThird = Convert.ToInt32(size.Width / 3); int secondThird = Convert.ToInt32(firstThird * 2); pause.AddRectangle(new RectangleF(0, 0, firstThird, size.Height)); pause.AddRectangle(new RectangleF(secondThird, 0, firstThird, size.Height)); return(pause); }
public void Draw(Point cur) { switch (sh) { case Shape.pencil: g.DrawLine(pen, prev, cur); prev = cur; break; case Shape.rectangle: path = new GraphicsPath(); if (prev.X > cur.X) { if (prev.Y > cur.Y) path.AddRectangle(new Rectangle(cur.X, cur.Y, prev.X - cur.X, prev.Y - cur.Y)); if (prev.Y < cur.Y) path.AddRectangle(new Rectangle(cur.X, prev.Y, prev.X - cur.X, cur.Y - prev.Y)); } else { if ((prev.Y < cur.Y)) path.AddRectangle(new Rectangle(prev.X, prev.Y, cur.X - prev.X, cur.Y - prev.Y)); else path.AddRectangle(new Rectangle(prev.X, cur.Y, cur.X - prev.X, prev.Y - cur.Y)); } break; case Shape.circle: path = new GraphicsPath(); path.AddEllipse(new Rectangle(prev.X, prev.Y, cur.X - prev.X, cur.Y - prev.Y)); break; case Shape.line: path = new GraphicsPath(); path.AddLine(prev, cur); break; case Shape.triangle: path = new GraphicsPath(); Point[] pp = new Point[3]; pp[0] = prev; pp[1] = cur; pp[2] = new Point(cur.X - 2 * (cur.X - prev.X), cur.Y); path.AddPolygon(pp); break; case Shape.erasor: path = null; g.DrawLine(er, prev, cur); prev = cur; break; default: break; } picture.Refresh(); }
public void ctor_GraphicsPath () { GraphicsPath path = new GraphicsPath (); path.AddRectangle (rect); Region r1 = new Region (path); r1.Xor (r); Assert.IsTrue (r1.IsEmpty (t.Graphics)); }
//是否圖形包含的座標 public override bool Contains(Point point) { GraphicsPath path = new GraphicsPath(); path.FillMode = FillMode.Winding; path.AddRectangle(new System.Drawing.Rectangle(TopLeft.X, TopLeft.Y, AbsoluteSize.X, AbsoluteSize.Y)); return path.IsVisible(point.X, point.Y); }
private void showTitle() { GraphicsPath gPath = new System.Drawing.Drawing2D.GraphicsPath(); gPath.AddRectangle(new RectangleF(0, 0, this.Width, this.Height)); this.Region = new System.Drawing.Region(gPath); }
private GraphicsPath GetImageGraphicsPath() { Bitmap bitmap = new Bitmap(_Cell.GetInfoImage()); GraphicsPath graphicsPath = new GraphicsPath(); Color colorTransparent = bitmap.GetPixel(0, 0); for (int row = 0; row < bitmap.Height; row++) { for (int col = 0; col < bitmap.Width; col++) { if (bitmap.GetPixel(col, row) != colorTransparent) { int colOpaquePixel = col; int colNext; for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext++) { if (bitmap.GetPixel(colNext, row) == colorTransparent) break; } graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1)); col = colNext; } } } return (graphicsPath); }
/// <summary> /// Изчертава правоъгълника. /// </summary> /// <param name="graphics"></param> public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(Location, ModelSize)); path.Transform(this.TMatrix.TransformationMatrix); /** * Създава се Pen, който изчертава контура, като използва * цвят и дебелина (определят се от конструктора) **/ Pen pen = new Pen(this.BorderColor, this.BorderWidth); /* * Създава се SolidBrush, която изпълва фигурата, като използва * цвят (определя се от конструктора) */ SolidBrush brush = new SolidBrush(this.FillColor); /* * Функция на namespace System.Drawing.Drawing2D * Изпълва контура на елипсата чрез SolidBrush */ if (IS_FILLED) { graphics.FillPath(brush, path); } /* * Функция на namespace System.Drawing.Drawing2D * Изчертава контура на елипсата чрез Pen */ graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
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); } } } }
/// <summary> /// Функция вычисления вершин квадрата по двум смежным вершинам /// </summary> /// <param name="pt1">Первая вершина</param> /// <param name="pt2">Вторая вершина</param> /// <returns>Функция возвращает массив точек, являющихся вершинами квадрата</returns> PointF[] GetSquareVertices(PointF pt1, PointF pt2) { using (System.Drawing.Drawing2D.GraphicsPath square = new System.Drawing.Drawing2D.GraphicsPath()) { //Разность координат (с учётом знака) float deltaX = pt1.X - pt2.X, deltaY = pt1.Y - pt2.Y; //Расстояние между точками float dist = (float)Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); //Угол наклона стороны double angle; //Прямоугольник с вычисленной длиной стороны square.AddRectangle(RectangleF.FromLTRB(0, 0, dist, dist)); //Вычисление угла поворота angle = Math.Atan(deltaY / deltaX); //Посколько функция Math.Atan возвращает угол в пределах [-π/2;π/2], //то нужно пересчитать его в пределы [0;2π]. Для этого смотрим знак разности координат. //Квадранты считаются с правого нижнего против часовой стрелки. //Первый квадрант [0;π/2) получается сам собой при вычислении арктангенса if ((deltaX > 0 && deltaY <= 0) || (deltaX >= 0 && deltaY > 0)) {//Второй квадрант [π/2;π) или третий квадрант [π;3π/2) angle = Math.PI + angle; } else if (deltaX <= 0 && deltaY > 0) {//Четвёртый квадрант [3π/2;2π) angle = 2 * Math.PI + angle; } //Перевод угла из радиан в градусы angle *= 180 / Math.PI; //Перенос начала координат в первую точку и //поворот прямоугольника на вычисленный угол относительно этого нового начала координат using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, pt.X, pt.Y)) { m.RotateAt((float)angle, new PointF()); square.Transform(m); } return square.PathPoints; } }
public override GraphicsPath GetGraphicsPath(int left, int top) { GraphicsPath p = new GraphicsPath(); Rectangle r = new Rectangle(left, top, Width, Height); p.AddRectangle(r); return p; }
public override bool ClickableAt(int x, int y) { Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS) + 10; Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR); // If we clicked inside the rectangle and it's visible we are clickable at. if (!Color.Transparent.Equals(fillColor)) { if (rect.Contains(x, y)) { return true; } } // check the rest of the lines if (lineThickness > 0) { using (Pen pen = new Pen(Color.White, lineThickness)) { using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(rect); return path.IsOutlineVisible(x, y, pen); } } } else { return false; } }
public override void Render(MarkupDrawContext d) { d.HyperLink = true; d.HyperlinkStyle = GetHyperlinkStyle(); if (!d.HyperlinkStyle.BackColor.IsEmpty) { using (GraphicsPath gp = new GraphicsPath()) { MarkupElementCollection col = this.Parent.Elements; int start = col.IndexOf(this) + 1; for (int i = start; i < col.Count; i++) { MarkupElement elem = col[i]; if (!elem.Visible) continue; if (elem is EndMarkupElement && ((EndMarkupElement)elem).StartElement == this) break; gp.AddRectangle(elem.RenderBounds); } using (SolidBrush brush = new SolidBrush(d.HyperlinkStyle.BackColor)) d.Graphics.FillPath(brush, gp); } } SetForeColor(d); }
protected override GraphicsPath CreateFlagPath(Rectangle rect) { PointF tf = new PointF(rect.X + (((float)rect.Width) / 2f), rect.Y + (((float)rect.Height) / 2f)); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(tf.X - 6f, tf.Y + 1f, 12f, 3f)); return path; }
protected override GraphicsPath GeneratePath() { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new Rectangle( Location.X, Location.Y, Size.Width, Size.Height)); return path; }
protected override void OnPaintBackground(PaintEventArgs e) { int _xPosStart = (ShowBorder) ? 0 : -1; Rectangle _panelRec = new Rectangle(_xPosStart, _xPosStart, Width - (_xPosStart * 2) - 1, Height - (_xPosStart * 2) - 1); Graphics _gFx = e.Graphics; _gFx.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath _gFxPathPanel = new GraphicsPath()) { _gFxPathPanel.AddRectangle(_panelRec); using (Pen _pen = new Pen(BorderColor, 1)) { if (ShowBorder) { _gFx.DrawPath(_pen, _gFxPathPanel); } } using (SolidBrush _sb = new SolidBrush(BackColor)) { _gFx.FillPath(_sb, _gFxPathPanel); } } }
public void child_Paint(object sender, PaintEventArgs e) { GraphicsPath path = new GraphicsPath(); path.AddRectangle(this.ClientRectangle); Region region = new Region(path); this.Region = region; }
//public static List<Rectangle> GetRectangle(Bitmap bitmap) //{ // List<Rectangle> rectList = new List<Rectangle>(); // int w = bitmap.Width; // int h = bitmap.Height; // Color color; // for (int row = 0; row < h; row++) // { // for (int col = 0; col < w; col++) // { // color = bitmap.GetPixel(col, row); // if (color.A > 0) // { // } // } // } // return rectList; //} /// <summary> /// 根据图片得到一个图片非透明部分的区域 /// </summary> /// <param name="bckImage"></param> /// <returns></returns> public static unsafe Region GetRegion(Bitmap bckImage) { GraphicsPath path = new GraphicsPath(); int w = bckImage.Width; int h = bckImage.Height; BitmapData bckdata = null; try { bckdata = bckImage.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); uint* bckInt = (uint*)bckdata.Scan0; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { if ((*bckInt & 0xff000000) != 0) { path.AddRectangle(new Rectangle(i, j, 1, 1)); } bckInt++; } } bckImage.UnlockBits(bckdata); bckdata = null; } catch { if (bckdata != null) { bckImage.UnlockBits(bckdata); bckdata = null; } } Region region = new Region(path); path.Dispose(); path = null; return region; }
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); } } }
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 GraphicsPath GetRoundedRectangle(RectangleF rect, float arcRadius) { var x = rect.X; var y = rect.Y; var w = rect.Width; var h = rect.Height; var d = 2 * arcRadius; var gp = new GraphicsPath(); if(arcRadius == 0) { gp.AddRectangle(rect); } else { gp.AddArc(x, y, d, d, 180, 90); gp.AddLine(x + arcRadius, y, x + w - arcRadius - 1, y); gp.AddArc(x + w - d - 1, y, d, d, 270, 90); gp.AddLine(x + w - 1, y + arcRadius, x + w - 1, y + h - arcRadius - 1); gp.AddArc(x + w - d - 1, y + h - d - 1, d, d, 0, 90); gp.AddLine(x + w - arcRadius - 1, y + h - 1, x + arcRadius, y + h - 1); gp.AddArc(x, y + h - d - 1, d, d, 90, 90); gp.AddLine(x, y + h - arcRadius - 1, x, y + arcRadius); } gp.CloseFigure(); return gp; }
//-------------------------------------------------------------------- public static GraphicsPath createRoundRect(int x, int y, int width, int height, int radius) { GraphicsPath gp = new GraphicsPath(); if (radius == 0) gp.AddRectangle(new Rectangle(x, y, width, height)); else { gp.AddLine(x + radius, y, x + width - radius, y); gp.AddArc(x + width - radius, y, radius, radius, 270, 90); gp.AddLine(x + width, y + radius, x + width, y + height - radius); gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90); gp.AddLine(x + width - radius, y + height, x + radius, y + height); gp.AddArc(x, y + height - radius, radius, radius, 90, 90); gp.AddLine(x, y + height - radius, x, y + radius); gp.AddArc(x, y, radius, radius, 180, 90); gp.CloseFigure(); } return gp; }
/// <summary> /// コンストラクタ /// </summary> public ConfigrationForm() { InitializeComponent(); // label8 //自分自身のバージョン情報を取得する System.Diagnostics.FileVersionInfo ver = System.Diagnostics.FileVersionInfo.GetVersionInfo( System.Reflection.Assembly.GetExecutingAssembly().Location); this.label8.Text = ver.ProductName + " version " + ver.ProductVersion + "\nCopyright © 2014 Real Pot Systems (TAKUBON). All right reserved."; // バッテリーの有無でラベルのdisableにする // バッテリーの有無 if ((SystemInformation.PowerStatus.BatteryChargeStatus & BatteryChargeStatus.NoSystemBattery) == BatteryChargeStatus.NoSystemBattery) { this._Battery.Enabled = false; this.label2.Enabled = false; } // パスを設定して、右上のボタンだけにする m_path = new GraphicsPath(); m_path.FillMode = FillMode.Winding; m_path.AddRectangle(new Rectangle(this.Width - 42, 0, 36, 36)); this.Region = new Region(m_path); this.SetPostion(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.WorkingArea.Top); SetButtonText(); }
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor) { PixelFormat pf; int w = bmp.Width + 2; int h = bmp.Height + 2; if (bkColor == Color.Transparent) { pf = PixelFormat.Format32bppArgb; } else { pf = bmp.PixelFormat; } Bitmap tmp = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tmp); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, (float)w, (float)h)); Matrix mtrx = new Matrix(); mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf); g = Graphics.FromImage(dst); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tmp, 0, 0); g.Dispose(); tmp.Dispose(); return dst; }
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); } }
///<summary> /// Creates a <see cref="PathPointSymbolizer"/> that renders rectangles. ///</summary> ///<param name="line">The pen to outline the rectangle</param> ///<param name="fill">the brush to fill the rectangle</param> ///<param name="width">The width of the rectangle</param> ///<param name="height">The height of the rectangle</param> ///<returns>The PathPointSymbolizer object</returns> public static PathPointSymbolizer CreateRectangle(Pen line, Brush fill, float width, float height) { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(-0.5f * width, -0.5f * height, width, height)); return new PathPointSymbolizer( new[] { new PathDefinition { Line = line, Fill = fill, Path = path } }); }
//檢查座標x,y是否在圖形內 public override bool ContainsInShape(int x, int y) { GraphicsPath path = new GraphicsPath(); path.FillMode = FillMode.Winding; path.AddRectangle(new Rectangle(_locationOfTopPoint, new Size(Wideth, Height))); return path.IsVisible(x, y); }
private GraphicsPath CreateRoundRect(Rectangle rect, int radius) { GraphicsPath gp = new GraphicsPath(); int x = rect.X; int y = rect.Y; int width = rect.Width; int height = rect.Height; if (radius > 0) { radius = Math.Min(radius, height / 2 - 1); radius = Math.Min(radius, width / 2 - 1); gp.AddLine(x + radius, y, x + width - (radius * 2), y); gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); gp.AddLine(x, y + height - (radius * 2), x, y + radius); gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); } else { gp.AddRectangle(rect); } gp.CloseFigure(); return gp; }
public Bitmap RotateImg(Bitmap bmp, float angle) { var bkColor = Color.White; int w = bmp.Width; int h = bmp.Height; PixelFormat pf; pf = bkColor == Color.Transparent ? PixelFormat.Format32bppArgb : bmp.PixelFormat; Bitmap tempImg = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tempImg); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, w, h)); Matrix mtrx = new Matrix(); //Using System.Drawing.Drawing2D.Matrix class mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf); g = Graphics.FromImage(newImg); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tempImg, 0, 0); g.Dispose(); tempImg.Dispose(); return newImg; }
// ======================================================================== // Attributes #region === Attributes #endregion // ======================================================================== // Con- / Destruktion #region === Con- / Destruktion #endregion // ======================================================================== // Properties #region === Properties #endregion // ======================================================================== // Methods #region === Methods public static GraphicsPath GetPath(this Region region) { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new Rectangle(0,0,100,100)); return path; }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(Location.X, Location.Y, ModelSize.Width, ModelSize.Width)); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
private void hideTitle() { GraphicsPath gPath = new System.Drawing.Drawing2D.GraphicsPath(); // gPath.AddEllipse(0, 25, this.ClientSize.Width, (this.ClientSize.Height/2)); int hh = (this.Height - this.ClientSize.Height); gPath.AddRectangle(new RectangleF(10, hh, this.Width - 20, this.Height - hh - 10)); this.Region = new System.Drawing.Region(gPath); }
public bool AddBorder(string originalFile, Color borderColor, int borderTopWidth, int borderLeftWidth, int borderRigthWidth, int borderBottomWidth) { try { Image image = new Bitmap(originalFile); int ImgWidth = image.Width; int ImgHeight = image.Height; int iWidth = ImgWidth + borderLeftWidth + borderRigthWidth; int iHeigth = ImgHeight + borderTopWidth + borderBottomWidth; Image imageOut = new Bitmap(iWidth, iHeigth); Graphics draw = Graphics.FromImage(imageOut); SolidBrush Brush = new SolidBrush(borderColor); System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath(); graphPath.AddRectangle(new Rectangle(0, 0, iWidth, iHeigth)); // Fill graphics path to screen. draw.FillPath(Brush, graphPath); draw.DrawImage(image, borderLeftWidth, borderTopWidth); //临时的,加纯色边框,黑线 //draw.FillPolygon(Brush, new Point[4] { new Point(80, 0), new Point(100, 0), new Point(0, 100), new Point(0, 80) }); draw.FillPolygon(Brush, new Point[4] { new Point(80, 0), new Point(0, 100), new Point(0, 80), new Point(100, 0) }); image.Dispose(); //删除原始文件 if (File.Exists(originalFile)) { File.Delete(originalFile); } //保存新文件 imageOut.Save(originalFile, ImageFormat.Jpeg); imageOut.Dispose(); draw.Dispose(); if (receiveMessage != null) { receiveMessage(string.Format("添加边框成功:“{0}”", originalFile)); } return(true); } catch (Exception ex) { if (receiveMessage != null) { receiveMessage(string.Format("添加边框失败:“{0}”,错误:{1}", originalFile, ex)); } return(false); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // path.AddEllipse(0, 0, this.Width, this.Height); Rectangle ret = new Rectangle(0, 0, this.Width, this.Height); path.AddRectangle(ret); this.Region = new Region(path); Graphics ex = this.CreateGraphics(); Rectangle retc = new Rectangle(10, 10, 180, 180); Rectangle retd = new Rectangle(35, 35, 130, 130); Rectangle rete = new Rectangle(40, 40, 120, 120); Rectangle retf = new Rectangle(65, 65, 70, 70); Rectangle retg = new Rectangle(70, 70, 60, 60); System.Drawing.Font strname_ok_ng = new System.Drawing.Font("黑体", 15, FontStyle.Bold); System.Drawing.Font strname = new System.Drawing.Font("黑体", 10, FontStyle.Bold); StringFormat ss = new StringFormat(StringFormatFlags.DirectionVertical); ex.DrawArc(new Pen(Draw_Color), retc, 180, 180); ex.DrawArc(new Pen(Draw_Color), retd, 180, 180); ex.FillPie(new SolidBrush(Draw_Color), retc, 180, 180); ex.FillPie(new SolidBrush(Color.Red), retc, 180, Percentage); //百分比100% ex.FillPie(Brushes.White, retd, 180, 180); ex.DrawArc(new Pen(Draw_Color), rete, 180, 180); ex.DrawArc(new Pen(Draw_Color), retf, 180, 180); ex.FillPie(new SolidBrush(Draw_Color), rete, 180, 180); ex.FillPie(new SolidBrush(Color.Red), rete, 180, Percentage_current); //百分比100% ex.FillPie(Brushes.White, retf, 180, 180); ex.DrawArc(new Pen(Color.Red), retg, 180, 180); ex.FillPie(Brushes.Red, retg, 360, 360); ex.DrawString("OK", strname_ok_ng, Brushes.White, 90, 90, StringFormat.GenericTypographic); ex.DrawString(System.DateTime.Now.ToString("d"), strname_ok_ng, Brushes.Black, 20, 140, StringFormat.GenericTypographic); }
protected GraphicsPath GetGraphicsPath(Rectangle rect) { GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath(); if (rect.Width <= 0) { rect.Width = 1; } if (rect.Height <= 0) { rect.Height = 1; } ClientPath.AddRectangle(rect); ClientPath.CloseFigure(); return(ClientPath); }
public static SD2D.GraphicsPath RoundRect(RectangleF rectangle, float roundRadius) { var path = new SD2D.GraphicsPath(); roundRadius = Math.Min(roundRadius, Math.Min(rectangle.Width / 2, rectangle.Height / 2)); if (roundRadius <= 1) { path.AddRectangle(rectangle.ToSystemDrawingObject()); return(path); } RectangleF innerRect = RectangleF.Inflate(rectangle, -roundRadius, -roundRadius); path.StartFigure(); path.AddArc(RoundBounds(innerRect.Right - 1, innerRect.Bottom - 1, roundRadius), 0, 90); path.AddArc(RoundBounds(innerRect.Left, innerRect.Bottom - 1, roundRadius), 90, 90); path.AddArc(RoundBounds(innerRect.Left, innerRect.Top, roundRadius), 180, 90); path.AddArc(RoundBounds(innerRect.Right - 1, innerRect.Top, roundRadius), 270, 90); path.CloseFigure(); return(path); }
public void Draw(Graphics g) { GraphicsUnit units = GraphicsUnit.Point; RectangleF imgRectangleF = mPictureBox.Image.GetBounds(ref units); Rectangle bigRectangle = Rectangle.Round(imgRectangleF); Region rgn = new Region(bigRectangle); //new Region(new Rectangle(50, 50, 200, 150)); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(rect); rgn.Exclude(path); //param 1 = opacity, 0 = transparent, 255 = Opaque //param 2,3,4 = RGB, 0 = Black, 255 = White Brush brush = new SolidBrush(Color.FromArgb(180, 10, 10, 10)); g.FillRegion(brush, rgn); Pen WhitePen = new Pen(Color.White, 2); g.DrawRectangle(WhitePen, rect); // Set the SmoothingMode property to smooth the line. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; SolidBrush whiteBrush = new SolidBrush(Color.White); Pen blackPen = new Pen(Color.Black, 1); if (!iPrint.WizardPageEditor.passport) { foreach (PosSizableRect pos in Enum.GetValues(typeof(PosSizableRect))) { g.FillEllipse(whiteBrush, GetRect(pos)); g.DrawEllipse(blackPen, GetRect(pos)); } } }
private void DrawRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius) { Point top = new Point((int)X, (int)Y); Point bottom = new Point((int)X, (int)(Y + height)); GPath = new GraphicsPath(); if (RoundedCorners) { GPath.AddLine(X + radius, Y, X + width - (radius * 2), Y); GPath.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90); GPath.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2)); GPath.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90); GPath.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height); GPath.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90); GPath.AddLine(X, Y + height - (radius * 2), X, Y + radius); GPath.AddArc(X, Y, radius * 2, radius * 2, 180, 90); GPath.CloseFigure(); } else { GPath.AddRectangle(new Rectangle(top, new Size((int)width, (int)height))); } if (HasFocus) { g.FillPath(new LinearGradientBrush(top, bottom, FocusBackColor1, FocusBackColor2), GPath); } else { g.FillPath(new LinearGradientBrush(top, bottom, BackColor1, BackColor2), GPath); } g.DrawPath(p, GPath); // Increase size of GPath for hit-testing purposes GPath = new GraphicsPath(); top.Offset(-2, -2); GPath.AddRectangle(new Rectangle(top, new Size((int)width + 4, (int)height + 4))); }
/// <summary> /// Builds the rounded rectangle. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="roundness">The roundness.</param> /// <returns>GraphicsPath.</returns> /// <exception cref="System.ArgumentException">Roundess value must be greater than -1!</exception> internal GraphicsPath BuildRoundedRectangle(Rectangle bounds, byte roundness) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); if (roundness < 0) { throw new ArgumentException("Roundess value must be greater than -1!"); } if (roundness == 0) { gp.AddRectangle(bounds); } else { gp.AddArc(bounds.Right - roundness, bounds.Top, roundness, roundness, 270, 90); gp.AddArc(bounds.Right - roundness, bounds.Bottom - roundness, roundness, roundness, 0, 90); gp.AddArc(bounds.Left, bounds.Bottom - roundness, roundness, roundness, 90, 90); gp.AddArc(bounds.Left, bounds.Top, roundness, roundness, 180, 90); gp.CloseAllFigures(); } return(gp); }
/// <summary> /// Rotate the image by angle degrees, with bkColor as new background /// Uses some magic with the translatetransform and pixel2d :P WOW! /// </summary> /// <param name="bmp">the image to be rotated</param> /// <param name="angle">the angle to rotate by</param> /// <param name="bkColor">background color for new background pixels</param> /// <returns>bmp rotated by angle degrees</returns> public static Bitmap RotateImg(Bitmap bmp, float angle, Color bkColor) { int w = bmp.Width; int h = bmp.Height; System.Drawing.Imaging.PixelFormat pf = default(System.Drawing.Imaging.PixelFormat); if (bkColor == Color.Transparent) { pf = System.Drawing.Imaging.PixelFormat.Format32bppArgb; } else { pf = bmp.PixelFormat; } Bitmap tempImg = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tempImg); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, w, h)); System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.Matrix(); mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf); g = Graphics.FromImage(newImg); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tempImg, 0, 0); g.Dispose(); tempImg.Dispose(); return(newImg); }
//</snippet9> // The following code example demonstrates how to use the // TranslateTransform method. This example is designed to be used // with Windows Forms. Create a form and paste the following code // into it. Call the TranslateAndTransform method in the form's // Paint event-handling method, passing e as PaintEventArgs. //<snippet10> private void TranslateAndTransform(PaintEventArgs e) { // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); // Create a rectangle. RectangleF layoutRectangle = new RectangleF(20.0F, 20.0F, 40.0F, 50.0F); // Add the rectangle to the path. myPath.AddRectangle(layoutRectangle); // Add a string to the path. myPath.AddString("Path", this.Font.FontFamily, 2, 10.0F, layoutRectangle, new StringFormat(StringFormatFlags.NoWrap)); // Draw the path. e.Graphics.DrawPath(Pens.Black, myPath); // Call TranslateTransform and draw the path again. e.Graphics.TranslateTransform(10.0F, 10.0F); e.Graphics.DrawPath(Pens.Red, myPath); }
public virtual void Draw(Graphics g, Point startPoint, Point endPoint) { if (startPoint == endPoint) { return; } MidPoint = ShapeHelper.GetLineMidPoint(startPoint, endPoint); GPath = new System.Drawing.Drawing2D.GraphicsPath(); //GPath.AddLine(startPoint, endPoint); Point pointA = new Point(startPoint.X + 16, startPoint.Y); Point pointB = new Point(endPoint.X - 16, endPoint.Y); GPath.AddLine(pointA, pointB); // OutOfMemoryException if two points equal if (pointA != pointB) { try { GPath.Widen(new Pen(Color.Red, 50F)); } catch { // Do nothing } } g.DrawLine(ArrowPen, startPoint, endPoint); bool isHorizontal = startPoint.Y == endPoint.Y; bool isVertical = startPoint.X == endPoint.X; GPathFinishEnd = new GraphicsPath(); GPathStartEnd = new GraphicsPath(); if ((IsFocused || !ShowEndTextOnlyWhenFocused) || (!string.IsNullOrEmpty(MiddleText) && !ShowMiddleTextOnlyWhenFocused)) { int textHeight = (int)Math.Ceiling(g.MeasureString("A", Font).Height); double angle = ShapeHelper.GetAngleBetween2PointsInDegrees(startPoint, endPoint); if ((IsFocused || !ShowEndTextOnlyWhenFocused) && !String.IsNullOrEmpty(StartText)) { SizeF textSize = g.MeasureString(StartText, Font); int textLength = (int)Math.Ceiling(textSize.Width); Point textPoint = ShapeHelper.GetPointAlongLine(startPoint, endPoint, 35); if (isHorizontal) { if (startPoint.X < endPoint.X) { textPoint.X = startPoint.X + 10; textPoint.Y -= textHeight + 2; } else { textPoint.X = startPoint.X - textLength - 5; textPoint.Y = startPoint.Y + 2; } } else if (isVertical) { if (startPoint.Y > endPoint.Y) { textPoint.X = startPoint.X - textLength / 2; textPoint.Y = startPoint.Y - textHeight * 2; } else { textPoint.X = startPoint.X - textLength / 2; textPoint.Y = startPoint.Y + textHeight; } } else { textPoint.X = textPoint.X - textLength / 2; textPoint.Y -= textHeight / 2; } EndRectangle1 = new Rectangle(textPoint, new Size(textLength, textHeight)); if (!isHorizontal && !isVertical) { g.FillRectangle(BackBrush, EndRectangle1); } g.DrawString(StartText, Font, TextBrush, textPoint); GPathFinishEnd.AddRectangle(EndRectangle1); GPathStartImage = new GraphicsPath(); if (IsFocused && StartImage != null) { //StartImageRectangle = new Rectangle(EndRectangle1.Left - StartImage.Width - 2, EndRectangle1.Top, StartImage.Width, StartImage.Height); StartImageRectangle = new Rectangle(EndRectangle1.Right + 2, EndRectangle1.Top, StartImage.Width, StartImage.Height); g.FillRectangle(BackBrush, StartImageRectangle); g.DrawImage(StartImage, StartImageRectangle); GPathStartImage.AddRectangle(StartImageRectangle); } } if ((IsFocused || !ShowEndTextOnlyWhenFocused) && !string.IsNullOrEmpty(EndText)) { int textLength = (int)Math.Ceiling(g.MeasureString(EndText, Font).Width); Point textPoint = ShapeHelper.GetPointAlongLine(endPoint, startPoint, 35); if (isHorizontal) { if (startPoint.X < endPoint.X) { textPoint.X = endPoint.X - textLength - 5; textPoint.Y = endPoint.Y + 2; } else { textPoint.X = endPoint.X + 10; textPoint.Y -= textHeight + 2; } } else if (isVertical) { if (startPoint.Y > endPoint.Y) { textPoint.X = endPoint.X - textLength / 2; textPoint.Y = endPoint.Y + textHeight; } else { textPoint.X = endPoint.X - textLength / 2; textPoint.Y = endPoint.Y - textHeight * 2; } } else { textPoint.X = textPoint.X - textLength / 2; textPoint.Y -= textHeight / 2; } EndRectangle2 = new Rectangle(textPoint, new Size(textLength, textHeight)); if (!isHorizontal && !isVertical) { g.FillRectangle(BackBrush, EndRectangle2); } g.DrawString(EndText, Font, TextBrush, textPoint); GPathStartEnd.AddRectangle(EndRectangle2); GPathEndImage = new GraphicsPath(); if (IsFocused && StartImage != null) { //EndImageRectangle = new Rectangle(EndRectangle2.Right + 2, EndRectangle2.Bottom - EndImage.Height, EndImage.Width, EndImage.Height); EndImageRectangle = new Rectangle(EndRectangle2.Left - EndImage.Width - 2, EndRectangle2.Bottom - EndImage.Height, EndImage.Width, EndImage.Height); g.FillRectangle(BackBrush, EndImageRectangle); g.DrawImage(EndImage, EndImageRectangle); GPathEndImage.AddRectangle(EndImageRectangle); } } if (!string.IsNullOrEmpty(MiddleText) && (IsFocused || !ShowMiddleTextOnlyWhenFocused)) { int textLength = (int)Math.Ceiling(g.MeasureString(MiddleText, Font).Width); Point textPoint = MidPoint; if (isHorizontal) { textPoint.X = textPoint.X - textLength / 2; textPoint.Y -= textHeight + 2; if (MiddleImage != null) { textPoint.Y -= MiddleImage.Height; } } else { textPoint.X = textPoint.X - textLength / 2; textPoint.Y -= textHeight * MiddleTextLineCount + MiddleImage.Height / 2 + 2; } g.FillRectangle(BackBrush, new Rectangle(textPoint.X, textPoint.Y, textLength, textHeight * MiddleTextLineCount)); g.DrawString(MiddleText, Font, TextBrush, textPoint); } } GPathMiddleImage = new System.Drawing.Drawing2D.GraphicsPath(); Image image; if (!IsFocused) { image = MiddleImage; } else { image = MiddleImageFocused != null ? MiddleImageFocused : MiddleImage; } if (image != null) { Point imagePos = MidPoint; imagePos.Offset(-1 * image.Width / 2, -1 * image.Height / 2); MiddleImageRectangle = new Rectangle(imagePos, image.Size); g.FillRectangle(BackBrush, MiddleImageRectangle); g.DrawImage(image, MiddleImageRectangle); GPathMiddleImage.AddRectangle(MiddleImageRectangle); } //#region Add circles at each end //int radius = 20; //Point circleCentre = ShapeHelper.GetPointAlongLine(startPoint, endPoint, radius); //GPathEnd1.AddPath(ShapeHelper.GetCirclePath(circleCentre, radius), false); ////g.DrawPath(new Pen(TextBrush), GPathEnd1); //circleCentre = ShapeHelper.GetPointAlongLine(endPoint, startPoint, radius); //GPathEnd2.AddPath(ShapeHelper.GetCirclePath(circleCentre, radius), false); ////g.DrawPath(new Pen(TextBrush), GPathEnd2); //#endregion }
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(); } }
protected override void OnDrawWindow(System.Windows.Forms.PaintEventArgs e, Skybound.VisualTips.VisualTip tip, Skybound.VisualTips.Rendering.VisualTipLayout layout) { System.Drawing.Drawing2D.GraphicsPath graphicsPath1; System.Drawing.Rectangle rectangle1 = layout.WindowBounds; bool flag = BackgroundEffect == Skybound.VisualTips.Rendering.VisualTipOfficeBackgroundEffect.Glass; if (RoundCorners) { graphicsPath1 = Skybound.VisualTips.Rendering.VisualTipRenderer.CreateRoundRectPath(rectangle1, Skybound.VisualTips.Rendering.VisualTipRenderer.LayeredWindowsSupported ? 5 : 7, Skybound.VisualTips.Rendering.VisualTipRenderer.BorderCorners.All); } else { graphicsPath1 = new System.Drawing.Drawing2D.GraphicsPath(); graphicsPath1.AddRectangle(new System.Drawing.Rectangle(rectangle1.Location, rectangle1.Size - (new System.Drawing.Size(1, 1)))); } using (System.Drawing.Brush brush = new System.Drawing.Drawing2D.LinearGradientBrush(rectangle1, BackColor, BackColorGradient, (float)(GradientAngle + (flag ? 180 : 0)), false)) { e.Graphics.FillPath(brush, graphicsPath1); } if (flag) { System.Drawing.Color color3 = BackColor; int i1 = (int)((1.0F - ((1.0F - color3.GetBrightness()) * 0.75F)) * 255.0F); System.Drawing.Color color1 = System.Drawing.Color.FromArgb(i1, i1, i1); using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(rectangle1, System.Drawing.Color.FromArgb(128, color1), System.Drawing.Color.FromArgb(0, color1), System.Drawing.Drawing2D.LinearGradientMode.Vertical)) using (System.Drawing.Drawing2D.GraphicsPath graphicsPath2 = CreateGlarePath(rectangle1, Skybound.VisualTips.Rendering.VisualTipRenderer.LayeredWindowsSupported ? 5 : 7)) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; e.Graphics.FillPath(linearGradientBrush, graphicsPath2); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; } } using (System.Drawing.Pen pen1 = new System.Drawing.Pen(BorderColor)) { if (Skybound.VisualTips.Rendering.VisualTipRenderer.LayeredWindowsSupported) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; } else { pen1.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; } e.Graphics.DrawPath(pen1, graphicsPath1); if (Skybound.VisualTips.Rendering.VisualTipRenderer.LayeredWindowsSupported) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; } } if (HasFooter(tip)) { System.Drawing.Rectangle rectangle2 = layout.GetElementBounds(Skybound.VisualTips.Rendering.VisualTipRenderElement.FooterImage); int i2 = rectangle2.Top - 6; System.Drawing.Color color4 = BackColorGradient; System.Drawing.Color color5 = BackColorGradient; System.Drawing.Color color6 = BackColorGradient; System.Drawing.Color color2 = System.Drawing.Color.FromArgb((int)((float)color4.R * 0.9F), (int)((float)color5.G * 0.9F), (int)((float)color6.B * 0.9F)); using (System.Drawing.Pen pen2 = new System.Drawing.Pen(color2)) { e.Graphics.DrawLine(pen2, rectangle1.X + 5, i2, rectangle1.Right - 6, i2); pen2.Color = System.Windows.Forms.ControlPaint.Light(BackColor); e.Graphics.DrawLine(pen2, rectangle1.X + 5, i2 + 1, rectangle1.Right - 6, i2 + 1); } } }
private void DrawAnalogBorder(Graphics g) { if (!AnalogDialRegionOnly) { g.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.Width, this.Height); } double DegStep = (DegHigh * 1.05 - DegLow / 1.05) / 19; double i = DegHigh * 1.05; double SinI, CosI; PointF[] curvePoints = new PointF[40]; for (int cp = 0; cp < 20; cp++) { i = i - DegStep; SinI = Math.Sin(i); CosI = Math.Cos(i); curvePoints[cp] = new PointF((float)(SinI * this.Width * 0.7 + this.Width / 2), (float)(CosI * this.Width * 0.7 + this.Height * 0.9)); curvePoints[38 - cp] = new PointF((float)(SinI * this.Width * 0.3 + this.Width / 2), (float)(CosI * this.Width * 0.3 + this.Height * 0.9)); } curvePoints[39] = curvePoints[0]; System.Drawing.Drawing2D.GraphicsPath dialPath = new System.Drawing.Drawing2D.GraphicsPath(); if (AnalogDialRegionOnly) { dialPath.AddPolygon(curvePoints); } else { dialPath.AddRectangle(new Rectangle(0, 0, this.Width, this.Height)); } this.Region = new System.Drawing.Region(dialPath); g.FillPolygon(new SolidBrush(DialBackColor), curvePoints); // Test moving this block if (!UseLedLightInAnalog) { DegStep = (DegHigh - DegLow) / (LedCount1 + LedCount2 + LedCount3 - 1); int lc = 0; int LedRadiusStart = (int)(this.Width * 0.6); if (!ShowTextInDial) { LedRadiusStart = (int)(this.Width * 0.65); } for (i = DegHigh; i > DegLow - DegStep / 2; i = i - DegStep) { //Graphics scale = g.Graphics; Pen scalePen = new Pen(Led3ColorOn, Led.Width); if (lc < LedCount1 + LedCount2) { scalePen = new Pen(Led2ColorOn, Led.Width); } if (lc < LedCount1) { scalePen = new Pen(Led1ColorOn, Led.Width); } lc++; SinI = Math.Sin(i); CosI = Math.Cos(i); g.DrawLine(scalePen, (int)((LedRadiusStart - Led.Height) * SinI + this.Width / 2), (int)((LedRadiusStart - Led.Height) * CosI + this.Height * 0.9), (int)(LedRadiusStart * SinI + this.Width / 2), (int)(LedRadiusStart * CosI + this.Height * 0.9)); scalePen.Dispose(); } } StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; float MeterFontSize = this.Font.SizeInPoints; if (this.Width > 0) { MeterFontSize = MeterFontSize * (float)(this.Width / 100f); } if (MeterFontSize < 4) { MeterFontSize = 4; } if (MeterFontSize > 72) { MeterFontSize = 72; } Font MeterFont = new Font(this.Font.FontFamily, MeterFontSize); g.DrawString(this.MeterText, MeterFont, new SolidBrush(this.ForeColor), this.Width / 2, this.Height * 0.43f, format); if (ShowDialText) { double DialTextStep = (DegHigh - DegLow) / (DialText.Length - 1); int dt = 0; MeterFontSize = MeterFontSize * 0.6f; int TextRadiusStart = (int)(this.Width * 0.64); for (i = DegHigh; i > DegLow - DialTextStep / 2; i = i - DialTextStep) { //Graphics scale = g.Graphics; Brush dtColor = new SolidBrush(DialTextHigh); StringFormat dtformat = new StringFormat(); dtformat.Alignment = StringAlignment.Center; dtformat.LineAlignment = StringAlignment.Center; try { if (int.Parse(DialText[dt]) < 0) { dtColor = new SolidBrush(DialTextLow); } if (int.Parse(DialText[dt]) == 0) { dtColor = new SolidBrush(DialTextNeutral); } } catch { dtColor = new SolidBrush(DialTextHigh); } Font dtfont = new Font(this.Font.FontFamily, MeterFontSize); SinI = Math.Sin(i); CosI = Math.Cos(i); g.DrawString(DialText[dt++], dtfont, dtColor, (int)(TextRadiusStart * SinI + this.Width / 2), (int)(TextRadiusStart * CosI + this.Height * 0.9), dtformat); } } }
protected System.Drawing.Drawing2D.GraphicsPath CreatePath() { System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath(); if (this.m_BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) { graphPath.AddRectangle(this.ClientRectangle); } else { //try //{ int curve = 0; System.Drawing.Rectangle rect = this.ClientRectangle; int offset = 0; if (this.m_BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle) { if (this.m_BorderWidth > 1) { offset = DoubleToInt(this.BorderWidth / 2); } curve = this.adjustedCurve; } else if (this.m_BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) { } else if (this.m_BorderStyle == System.Windows.Forms.BorderStyle.None) { curve = this.adjustedCurve; } if (curve == 0) { graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset)); } else { int rectWidth = rect.Width - 1 - offset; int rectHeight = rect.Height - 1 - offset; int curveWidth = 1; if ((this.m_CurveMode & CornerCurveModes.TopRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90); if ((this.m_CurveMode & CornerCurveModes.BottomRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90); if ((this.m_CurveMode & CornerCurveModes.BottomLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90); if ((this.m_CurveMode & CornerCurveModes.TopLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90); graphPath.CloseFigure(); } /*} [FXCOP] * catch (System.Exception) * { * graphPath.AddRectangle(this.ClientRectangle); * }*/ } return(graphPath); }
public static void Run() { // ExStart:ExtractBorder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); Document doc = new Document(dataDir + "input.pdf"); Stack graphicsState = new Stack(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)doc.Pages[1].PageInfo.Width, (int)doc.Pages[1].PageInfo.Height); System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); // Default ctm matrix value is 1,0,0,1,0,0 System.Drawing.Drawing2D.Matrix lastCTM = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 0); // System.Drawing coordinate system is top left based, while pdf coordinate system is low left based, so we have to apply the inversion matrix System.Drawing.Drawing2D.Matrix inversionMatrix = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, (float)doc.Pages[1].PageInfo.Height); System.Drawing.PointF lastPoint = new System.Drawing.PointF(0, 0); System.Drawing.Color fillColor = System.Drawing.Color.FromArgb(0, 0, 0); System.Drawing.Color strokeColor = System.Drawing.Color.FromArgb(0, 0, 0); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bitmap)) { gr.SmoothingMode = SmoothingMode.HighQuality; graphicsState.Push(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0)); // Process all the contents commands foreach (Operator op in doc.Pages[1].Contents) { Operator.GSave opSaveState = op as Operator.GSave; Operator.GRestore opRestoreState = op as Operator.GRestore; Operator.ConcatenateMatrix opCtm = op as Operator.ConcatenateMatrix; Operator.MoveTo opMoveTo = op as Operator.MoveTo; Operator.LineTo opLineTo = op as Operator.LineTo; Operator.Re opRe = op as Operator.Re; Operator.EndPath opEndPath = op as Operator.EndPath; Operator.Stroke opStroke = op as Operator.Stroke; Operator.Fill opFill = op as Operator.Fill; Operator.EOFill opEOFill = op as Operator.EOFill; Operator.SetRGBColor opRGBFillColor = op as Operator.SetRGBColor; Operator.SetRGBColorStroke opRGBStrokeColor = op as Operator.SetRGBColorStroke; if (opSaveState != null) { // Save previous state and push current state to the top of the stack graphicsState.Push(((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Clone()); lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek(); } else if (opRestoreState != null) { // Throw away current state and restore previous one graphicsState.Pop(); lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek(); } else if (opCtm != null) { System.Drawing.Drawing2D.Matrix cm = new System.Drawing.Drawing2D.Matrix( (float)opCtm.Matrix.A, (float)opCtm.Matrix.B, (float)opCtm.Matrix.C, (float)opCtm.Matrix.D, (float)opCtm.Matrix.E, (float)opCtm.Matrix.F); // Multiply current matrix with the state matrix ((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Multiply(cm); lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek(); } else if (opMoveTo != null) { lastPoint = new System.Drawing.PointF((float)opMoveTo.X, (float)opMoveTo.Y); } else if (opLineTo != null) { System.Drawing.PointF linePoint = new System.Drawing.PointF((float)opLineTo.X, (float)opLineTo.Y); graphicsPath.AddLine(lastPoint, linePoint); lastPoint = linePoint; } else if (opRe != null) { System.Drawing.RectangleF re = new System.Drawing.RectangleF((float)opRe.X, (float)opRe.Y, (float)opRe.Width, (float)opRe.Height); graphicsPath.AddRectangle(re); } else if (opEndPath != null) { graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } else if (opRGBFillColor != null) { fillColor = opRGBFillColor.getColor(); } else if (opRGBStrokeColor != null) { strokeColor = opRGBStrokeColor.getColor(); } else if (opStroke != null) { graphicsPath.Transform(lastCTM); graphicsPath.Transform(inversionMatrix); gr.DrawPath(new System.Drawing.Pen(strokeColor), graphicsPath); graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } else if (opFill != null) { graphicsPath.FillMode = FillMode.Winding; graphicsPath.Transform(lastCTM); graphicsPath.Transform(inversionMatrix); gr.FillPath(new System.Drawing.SolidBrush(fillColor), graphicsPath); graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } else if (opEOFill != null) { graphicsPath.FillMode = FillMode.Alternate; graphicsPath.Transform(lastCTM); graphicsPath.Transform(inversionMatrix); gr.FillPath(new System.Drawing.SolidBrush(fillColor), graphicsPath); graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); } } } dataDir = dataDir + "ExtractBorder_out_.png"; bitmap.Save(dataDir, ImageFormat.Png); // ExEnd:ExtractBorder Console.WriteLine("\nBorder extracted successfully as image.\nFile saved at " + dataDir); }
private System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle r, int radius, Corners corners) { //Make sure the Path fits inside the rectangle r.Width -= 1; r.Height -= 1; //Scale the radius if it's too large to fit. if (radius > (r.Width)) { radius = r.Width; } if (radius > (r.Height)) { radius = r.Height; } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (radius <= 0) { path.AddRectangle(r); } else if ((corners & Corners.TopLeft) == Corners.TopLeft) { path.AddArc(r.Left, r.Top, radius, radius, 180, 90); } else { path.AddLine(r.Left, r.Top, r.Left, r.Top); } if ((corners & Corners.TopRight) == Corners.TopRight) { path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90); } else { path.AddLine(r.Right, r.Top, r.Right, r.Top); } if ((corners & Corners.BottomRight) == Corners.BottomRight) { path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90); } else { path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom); } if ((corners & Corners.BottomLeft) == Corners.BottomLeft) { path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90); } else { path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom); } path.CloseFigure(); return(path); }