protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { int x0 = 55; int y0 = 30; System.Drawing.Graphics g = e.Graphics; //g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), 0, 0, 100, 100); for (int i = 0; i < 10; i++) { g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), x0, y0 + i * 20, x0 + 177, 30 + i * 20); if (i % 3 == 0) { g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), x0, y0 - 1 + i * 20, x0 + 177, 29 + i * 20); } if (i < 9) { for (int j = 0; j < 9; j++) { String myString = Tree.solution[i, j].ToString(); g.DrawString(myString, new System.Drawing.Font("Arial Bold", 13), new System.Drawing.SolidBrush(System.Drawing.Color.Red), x0 + 5 + i * 20, y0 + j * 20, new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic)); } } } for (int i = 0; i < 10; i++) { g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), x0 + 20 * i, y0, x0 + 20 * i, 30 + 9 * 20); if (i % 3 == 0) { g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), x0 - 1 + 20 * i, y0, x0 - 1 + 20 * i, 210); } } }
protected static void drawBuffer(System.Drawing.Graphics g) { //base.OnPaint(e); g.Clear(System.Drawing.Color.Black); //System.Console.WriteLine(i+ " " + x); g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White), 50, 0, i + 50, 100); wuerfel.punkte = Matrix.multiplizieren(wuerfel.punkte, drehmatrix1grad); //System.Console.WriteLine(i+ " " + y); g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White), 150, 0, j + 150, 150); for (int k = 0; k < 8; k++) { g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Color.Blue), center[0] - 2 + (int)wuerfel.punkte[k][0] + (int)(wuerfel.punkte[k][2] * 0.1), (int)center[1] - 2 + (int)(wuerfel.punkte[k][1] + wuerfel.punkte[k][2] * 0.1), 5, 5); } for (int l = 0; l < wuerfel.W.Length; l++) { wuerfel.W[l] = Matrix.multiplizieren(wuerfel.W[l], drehmatrix1grad); g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), (float)(center[0] + wuerfel.W[l][0][0] + wuerfel.W[l][0][2] * 0.1), (float)(center[1] + wuerfel.W[l][0][1] + wuerfel.W[l][0][2] * 0.1), (float)(center[0] + wuerfel.W[l][1][0] + wuerfel.W[l][1][2] * 0.1), (float)(center[1] + wuerfel.W[l][1][1] + wuerfel.W[l][1][2] * 0.1)); } g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White), i + 50, 100, j + 150, 150); }
public override void DrawKeyFrames(System.Drawing.Graphics g, int TimelineStartX, int ScrollbarStartIndex, int VisibleIndex) { foreach (KeyValuePair <int, VisibleAnimationObjectKeyFrame> Move in DicAnimationKeyFrame) { int KeyFrameStartPos = TimelineStartX + 2 + Move.Key * 8 - ScrollbarStartIndex; int KeyFrameVisibleWidth = 4; KeyFrameVisibleWidth = Math.Min(4, KeyFrameStartPos + 2 - TimelineStartX); if (KeyFrameVisibleWidth > 0) { g.FillRectangle(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(KeyFrameStartPos, 28 + VisibleIndex * 21, KeyFrameVisibleWidth, 4)); } if (Move.Value.NextKeyFrame != -1) {//Draw an arrow linking the 2 Key Frames. int ArrowLength = 3; int ArrowStartPos = TimelineStartX + Move.Value.NextKeyFrame * 8 - ArrowLength - ScrollbarStartIndex; ArrowLength = Math.Min(3, ArrowStartPos - TimelineStartX); KeyFrameStartPos = Math.Max(TimelineStartX, KeyFrameStartPos); if (ArrowLength > 0) { g.DrawLine(System.Drawing.Pens.Black, KeyFrameStartPos, 30 + VisibleIndex * 21, TimelineStartX + Move.Value.NextKeyFrame * 8 - 3 - ScrollbarStartIndex, 30 + VisibleIndex * 21); g.DrawLine(System.Drawing.Pens.Black, TimelineStartX + Move.Value.NextKeyFrame * 8 - ArrowLength - ScrollbarStartIndex, 30 + VisibleIndex * 21 - ArrowLength, TimelineStartX + Move.Value.NextKeyFrame * 8 - ScrollbarStartIndex, 30 + VisibleIndex * 21); g.DrawLine(System.Drawing.Pens.Black, TimelineStartX + Move.Value.NextKeyFrame * 8 - ArrowLength - ScrollbarStartIndex, 30 + VisibleIndex * 21 + ArrowLength, TimelineStartX + Move.Value.NextKeyFrame * 8 - ScrollbarStartIndex, 30 + VisibleIndex * 21); } } } }
private void ejeX(System.Drawing.Graphics g, int x, int paraY1, int paraY2, int i) { if (lejeX < 19) { //cambio //comenzamos con las medidas eje x g.DrawLine( new System.Drawing.Pen(System.Drawing.Color.Black, 1), new System.Drawing.Point(x, paraY1), new System.Drawing.Point(x, 20)); g.DrawLine( new System.Drawing.Pen(System.Drawing.Color.Black, 1), new System.Drawing.Point(x, paraY1), new System.Drawing.Point(x, paraY2)); g.DrawString("" + (i += 2), new System.Drawing.Font("Arial", 5), new System.Drawing.SolidBrush(System.Drawing.Color.Black), x, paraY1 + 10 //,drawFormat ); x += this.escala; lejeX++; ejeX(g, x, paraY1, paraY2, i); } }
private void ejeY(System.Drawing.Graphics g, int y, int paraX1, int paraX2, long i) { if (lejeY < 18) { //comienzo g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black, 1), new System.Drawing.Point(paraX1, y), new System.Drawing.Point(300, y)); //comenzamos con las medidas eje y g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black, 1), new System.Drawing.Point(paraX1, y), new System.Drawing.Point(paraX2, y)); //g.drawString(""+i, 0, y); //StringFormat drawFormat = new StringFormat(); //drawFormat.FormatFlags = StringFormatFlags.DirectionVertical; g.DrawString("" + i, new System.Drawing.Font("Arial", 5), new System.Drawing.SolidBrush(System.Drawing.Color.Black), 0, y //,drawFormat ); y += this.escala; lejeY++; ejeY(g, y, paraX1, paraX2, i - maximo / 17); } }
public static void Draw3DButton(System.Drawing.Graphics g, System.Drawing.Rectangle rect, bool isPressed) { // background WFRect bgRect = rect; //bgRect.Inflate(-1, -1); bgRect.Offset(1, 1); g.FillRectangle(isPressed ? RGBrushes.Black : RGBrushes.White, bgRect); // outter frame g.DrawLine(System.Drawing.Pens.Black, rect.X + 1, rect.Y, rect.Right - 1, rect.Y); g.DrawLine(System.Drawing.Pens.Black, rect.X + 1, rect.Bottom, rect.Right - 1, rect.Bottom); g.DrawLine(System.Drawing.Pens.Black, rect.X, rect.Y + 1, rect.X, rect.Bottom - 1); g.DrawLine(System.Drawing.Pens.Black, rect.Right, rect.Y + 1, rect.Right, rect.Bottom - 1); // content WFRect bodyRect = rect; bodyRect.Inflate(-1, -1); bodyRect.Offset(1, 1); g.FillRectangle(System.Drawing.Brushes.LightGray, bodyRect); // shadow g.DrawLines(isPressed ? RGPens.White : System.Drawing.Pens.DimGray, new System.Drawing.Point[] { new System.Drawing.Point(rect.Left + 1, rect.Bottom - 1), new System.Drawing.Point(rect.Right - 1, rect.Bottom - 1), new System.Drawing.Point(rect.Right - 1, rect.Top + 1), }); }
/// <summary> /// Draw border at specified position. /// </summary> /// <param name="g">Instance for graphics object.</param> /// <param name="x">X coordinate of start point.</param> /// <param name="y">Y coordinate of start point.</param> /// <param name="x2">X coordinate of end point.</param> /// <param name="y2">Y coordinate of end point.</param> /// <param name="style">Style flag of border.</param> /// <param name="color">Color of border.</param> /// <param name="bgPen">Fill pen used when drawing double outline.</param> public void DrawLine(PlatformGraphics g, RGFloat x, RGFloat y, RGFloat x2, RGFloat y2, BorderLineStyle style, SolidColor color, RGPen bgPen = null) { if (style == BorderLineStyle.None) { return; } RGPen p = pens[(byte)style]; lock (p) { p.Color = color; p.StartCap = System.Drawing.Drawing2D.LineCap.Square; p.EndCap = System.Drawing.Drawing2D.LineCap.Square; g.DrawLine(p, new RGPointF(x, y), new RGPointF(x2, y2)); } if (style == BorderLineStyle.DoubleLine && bgPen != null) { lock (bgPen) { g.DrawLine(bgPen, new RGPointF(x, y), new RGPointF(x2, y2)); } } }
public void drawALine(LinkedList [] l, System.Drawing.Color c) { System.Drawing.Graphics g = mainVars.getForm().CreateGraphics(); System.Drawing.Pen pen = new System.Drawing.Pen(c, 3); for (int i = l.Length - 1; i >= 0; i--) { LinkedListNode node = l[i].getHead().getNext(); while (node != null) { if (node.getData().right != null) { BinaryTreeeNode parent = node.getData(); int parent_midleX = parent.getButton().Location.X + (parent.getButton().Width / 2), parent_midleY = parent.getButton().Location.Y + parent.right.getButton().Height; int child_midlleX = parent.right.getButton().Location.X + (parent.right.getButton().Width / 2), child_midlleY = parent.right.getButton().Location.Y; g.DrawLine(pen, parent_midleX, parent_midleY, child_midlleX, child_midlleY); child_midlleX = parent.left.getButton().Location.X + (parent.left.getButton().Width / 2); child_midlleY = parent.left.getButton().Location.Y; g.DrawLine(pen, parent_midleX, parent_midleY, child_midlleX, child_midlleY); } node = node.getNext(); } } pen.Dispose(); }
private void DisegnaBordo(eLatoBordo b, System.Drawing.Graphics g, int w, int h) { var H = false; var W = false; if (b == eLatoBordo.H) { H = true; } if (b == eLatoBordo.W) { W = true; } if (b == eLatoBordo.HW) { H = true; W = true; } if (H) { g.DrawLine(cGB.myPenLeft, new System.Drawing.Point(0, 0), new System.Drawing.Point(0, h)); } if (W) { g.DrawLine(cGB.myPenBottom, new System.Drawing.Point(0, h), new System.Drawing.Point(w, h)); } }
private void rdbDrawScrnMatrix(System.Drawing.Graphics rdb) { int numxlines = this.scrnwidth / this.CharSize.Width; int numylines = this.scrnheight / this.CharSize.Height; int xpos = 0; int ypos = 0; for (int ix = 0; ix < numxlines; ix++) { xpos = this.CharSize.Width * ix; if (ix % 2 == 1) { rdbDrawString(rdb, ix.ToString(), xpos + 2, this.scrnheight - (this.CharSize.Height / 2), 6); } rdb.DrawLine(new System.Drawing.Pen(System.Drawing.Color.FromArgb(0x150000FF)), xpos, 0, xpos, this.scrnheight); } for (int iy = 0; iy < numylines; iy++) { ypos = this.CharSize.Height * iy; rdbDrawString(rdb, iy.ToString(), this.scrnwidth - this.CharSize.Width + 2, ypos, 6); rdb.DrawLine(new System.Drawing.Pen(System.Drawing.Color.FromArgb(0x150000FF)), 0, ypos, this.scrnwidth, ypos); } //this.rdbBitmap = new System.Drawing.Bitmap(this.CharSize.Width, this.CharSize.Height); //this.rdbGraphics = System.Drawing.Graphics.FromImage(this.rdbBitmap); //this.rdbGraphics.Clear(System.Drawing.Color.FromArgb(255, 181, 106)); //rdb.DrawImageUnscaled(this.rdbBitmap, mousepnt.X, mousepnt.Y); }
private void DrawGrid(System.Drawing.Graphics g) { g.DrawRectangle(CurrentPen as System.Drawing.Pen, new System.Drawing.Rectangle(0, 0, (int)szScreen.X, (int)szScreen.Y)); System.Drawing.Pen p1 = new System.Drawing.Pen(System.Drawing.Color.White, 1); System.Drawing.Pen p2 = new System.Drawing.Pen(System.Drawing.Color.White, 2); double gridSpacing = 10; double x = -(ptViewport.X); if (x % 10 != 0) { x -= (ptViewport.X % 10); } for (; x <= szViewport.X - ptViewport.X; x += gridSpacing) { g.DrawLine(x != 0 ? p1 : p2, viewportToScreen(new Point(x, -ptViewport.Y)), viewportToScreen(new Point(x, szScreen.Y))); } for (x = -(ptViewport.X); x <= szViewport.X - ptViewport.X; x += 1) { double hashSize = 1; if (x % 5 == 0) { hashSize = 2; } g.DrawLine(x != 0 ? p1 : p2, viewportToScreen(new Point(x, -hashSize)), viewportToScreen(new Point(x, hashSize))); } double y = -(ptViewport.Y); if (y % 10 != 0) { y -= (ptViewport.Y % 10); } for (; y <= szViewport.Y - ptViewport.Y; y += gridSpacing) { g.DrawLine(y != 0 ? p1 : p2, viewportToScreen(new Point(-ptViewport.X, y)), viewportToScreen(new Point(szScreen.X, y))); } for (y = -(ptViewport.Y); y <= szViewport.Y - ptViewport.Y; y += 1) { double hashSize = 1; if (y % 5 == 0) { hashSize = 2; } g.DrawLine(y != 0 ? p1 : p2, viewportToScreen(new Point(-hashSize, y)), viewportToScreen(new Point(hashSize, y))); } }
public static void Draw3ColorBar(System.Drawing.Graphics dc, System.Drawing.RectangleF r, System.Windows.Forms.Orientation orientation, System.Drawing.Color c1, System.Drawing.Color c2, System.Drawing.Color c3) { // to draw a 3 color bar 2 gradient brushes are needed // one from c1 - c2 and c2 - c3 var lr1 = r; var lr2 = r; float angle = 0; if (orientation == System.Windows.Forms.Orientation.Vertical) { angle = 270; lr1.Height = lr1.Height / 2; lr2.Height = r.Height - lr1.Height; lr2.Y += lr1.Height; } if (orientation == System.Windows.Forms.Orientation.Horizontal) { angle = 0; lr1.Width = lr1.Width / 2; lr2.Width = r.Width - lr1.Width; lr1.X = lr2.Right; } if (lr1.Height > 0 && lr1.Width > 0) { using (System.Drawing.Drawing2D.LinearGradientBrush lb2 = new System.Drawing.Drawing2D.LinearGradientBrush(lr2, c1, c2, angle, false), lb1 = new System.Drawing.Drawing2D.LinearGradientBrush(lr1, c2, c3, angle, false)) { dc.FillRectangle(lb1, lr1); dc.FillRectangle(lb2, lr2); } } // with some sizes the first pixel in the gradient rectangle shows the opposite color // this is a workaround for that problem if (orientation == System.Windows.Forms.Orientation.Vertical) { using (System.Drawing.Pen pc2 = new System.Drawing.Pen(c2, 1), pc3 = new System.Drawing.Pen(c3, 1)) { dc.DrawLine(pc3, lr1.Left, lr1.Top, lr1.Right - 1, lr1.Top); dc.DrawLine(pc2, lr2.Left, lr2.Top, lr2.Right - 1, lr2.Top); } } if (orientation == System.Windows.Forms.Orientation.Horizontal) { using (System.Drawing.Pen pc1 = new System.Drawing.Pen(c1, 1), pc2 = new System.Drawing.Pen(c2, 1), pc3 = new System.Drawing.Pen(c3, 1)) { dc.DrawLine(pc1, lr2.Left, lr2.Top, lr2.Left, lr2.Bottom - 1); dc.DrawLine(pc2, lr2.Right, lr2.Top, lr2.Right, lr2.Bottom - 1); dc.DrawLine(pc3, lr1.Right, lr1.Top, lr1.Right, lr1.Bottom - 1); } } }
public void rdbDrawCrossHair(System.Drawing.Graphics rdb) { if (this.mousepnt.Y < this.scrnheight && this.mousepnt.X < this.scrnwidth) { rdb.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Cyan), this.mousepnt.X, this.mousepnt.Y, this.scrnwidth, this.mousepnt.Y); rdb.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Cyan), this.mousepnt.X, 0, this.mousepnt.X, this.mousepnt.Y); rdb.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Cyan), 0, this.mousepnt.Y, this.mousepnt.X, this.mousepnt.Y); rdb.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Cyan), this.mousepnt.X, this.mousepnt.Y, this.mousepnt.X, this.scrnheight); } }
private void DrawHistogram() { const int Hist_W = 265, Hist_H = 265; Histogram = new System.Drawing.Bitmap(Hist_W, Hist_H, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(Histogram); System.Drawing.Pen mypen = new System.Drawing.Pen(System.Drawing.Color.Black, 1); g.FillRectangle(System.Drawing.Brushes.White, new System.Drawing.Rectangle(0, 0, _SrcImg.Width, _SrcImg.Height)); System.Drawing.PointF org = new System.Drawing.PointF(5, 260); g.DrawLine(mypen, org, new System.Drawing.PointF(265, 260)); // drawing x axis g.DrawLine(mypen, org, new System.Drawing.PointF(5, 0)); // drawing y axis try { if (_SrcImg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { DrawingHistogramSolidLine(Histogram, grayHis, System.Drawing.Color.Gray); // labeling min and max gray value position mypen = new System.Drawing.Pen(System.Drawing.Color.DarkBlue, Convert.ToSingle(1)); float[] dashValue = { 5, 5, 5, 5 }; mypen.DashPattern = dashValue; g.DrawLine(mypen, new System.Drawing.PointF(org.X + _Info.MinGray, org.Y - 1), new System.Drawing.PointF(org.X + _Info.MinGray, Convert.ToSingle(Hist_H) * Convert.ToSingle(0.1))); g.DrawLine(mypen, new System.Drawing.PointF(org.X + _Info.MaxGray, org.Y - 1), new System.Drawing.PointF(org.X + _Info.MaxGray, Convert.ToSingle(Hist_H) * Convert.ToSingle(0.1))); // lebeling some data on axis System.Drawing.Font font = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Regular); g.DrawString(_Info.MassGray.ToString(), font, System.Drawing.Brushes.Black, new System.Drawing.PointF(0, Convert.ToSingle(Hist_H) * Convert.ToSingle(0.1))); } else if (_SrcImg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb) { DrawingHistogramLine(Histogram, His_r, System.Drawing.Color.Red); DrawingHistogramLine(Histogram, His_g, System.Drawing.Color.Green); DrawingHistogramLine(Histogram, His_b, System.Drawing.Color.Blue); } else if (_SrcImg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb || _SrcImg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppRgb) { DrawingHistogramLine(Histogram, His_r, System.Drawing.Color.Red); DrawingHistogramLine(Histogram, His_g, System.Drawing.Color.Green); DrawingHistogramLine(Histogram, His_b, System.Drawing.Color.Blue); } } catch (SystemException ex) { System.Windows.Forms.MessageBox.Show("In ImageProc.DrawHistogram: " + ex.ToString()); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("In ImageProc.DrawHistogram: " + ex.ToString()); } finally { GC.Collect(); } }
public void dbug_HighlightMeNow(Rectangle rect) { using (System.Drawing.Pen mpen = new System.Drawing.Pen(System.Drawing.Brushes.White, 2)) using (System.Drawing.Graphics g = this.dbugCreateGraphics()) { System.Drawing.Rectangle r = rect.ToRect(); g.DrawRectangle(mpen, r); g.DrawLine(mpen, new System.Drawing.Point(r.X, r.Y), new System.Drawing.Point(r.Right, r.Bottom)); g.DrawLine(mpen, new System.Drawing.Point(r.X, r.Bottom), new System.Drawing.Point(r.Right, r.Y)); } }
private static void DrawOHLCBars(System.Drawing.Graphics graphics, OHLCBar[] bars) { for (int i = 0; i < bars.Length; i++) { float x = bars[i].Left + (bars[i].Width / 2); graphics.DrawLine(bars[i].Pen, x, bars[i].HighPoint.Y, x, bars[i].LowPoint.Y); graphics.DrawLine(bars[i].Pen, bars[i].Left + 1, bars[i].OpenPoint.Y, x, bars[i].OpenPoint.Y); graphics.DrawLine(bars[i].Pen, bars[i].Left + bars[i].Width - 1, bars[i].ClosePoint.Y, x, bars[i].ClosePoint.Y); } }
public string GeraImage(HttpContext pagina, string imgKey) { string strValida = imgKey; if (string.IsNullOrEmpty(strValida)) { strValida = ImageString(); } pagina.Response.ContentType = "image/jpeg"; pagina.Response.Clear(); pagina.Response.BufferOutput = true; System.Drawing.Bitmap img = new System.Drawing.Bitmap(_width, _height); System.Drawing.Graphics dr = System.Drawing.Graphics.FromImage(img); dr.FillRectangle(_backColor, new System.Drawing.Rectangle(0, 0, img.Width, img.Height)); System.Drawing.Font font = new System.Drawing.Font("Verdana", 18, System.Drawing.FontStyle.Bold); dr.DrawString(strValida, font, _color, rnd.Next(20), rnd.Next(_height - 24)); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(0, rnd.Next(_height)), new System.Drawing.Point(_width, rnd.Next(_height))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(0, rnd.Next(_height)), new System.Drawing.Point(_width, rnd.Next(_height))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(0, rnd.Next(_height)), new System.Drawing.Point(_width, rnd.Next(_height))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(0, rnd.Next(_height)), new System.Drawing.Point(_width, rnd.Next(_height))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(0, rnd.Next(_height)), new System.Drawing.Point(_width, rnd.Next(_height))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(rnd.Next(_width), 0), new System.Drawing.Point(_height, rnd.Next(_width))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(rnd.Next(_width), 0), new System.Drawing.Point(_height, rnd.Next(_width))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(rnd.Next(_width), 0), new System.Drawing.Point(_height, rnd.Next(_width))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(rnd.Next(_width), 0), new System.Drawing.Point(_height, rnd.Next(_width))); dr.DrawLine(new System.Drawing.Pen(_color), new System.Drawing.Point(rnd.Next(_width), 0), new System.Drawing.Point(_height, rnd.Next(_width))); for (int x = 0; x < img.Width; x++) { for (int y = 0; y < img.Height; y++) { if (rnd.Next(6) == 1) { img.SetPixel(x, y, _pointColor); } } } font.Dispose(); dr.Dispose(); img.Save(pagina.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); img.Dispose(); pagina.Response.Write(strValida); return(strValida); }
internal void Paint(object sender, System.Windows.Forms.PaintEventArgs e) { System.Drawing.Graphics g = e.Graphics; g.Flush(System.Drawing.Drawing2D.FlushIntention.Sync); float xMod = g.VisibleClipBounds.Width / 100; float yMod = g.VisibleClipBounds.Height / 60; float playerSize = ServerParam.Instance.Player_size * 2 * 5; float ballSize = ServerParam.Instance.Ball_size * 2 * 10; System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.White, xMod); System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.LightBlue, xMod); //added g.DrawLine(pen, xMod * 50, 0, xMod * 50, yMod * 60); g.DrawRectangle(pen, new System.Drawing.Rectangle((int)(xMod * 92), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14))); g.DrawRectangle(pen, new System.Drawing.Rectangle((int)(xMod * -5), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14))); g.DrawRectangle(pen2, new System.Drawing.Rectangle((int)(xMod * 43), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14)));//added g.DrawEllipse(pen, new System.Drawing.Rectangle((int)(xMod * 43), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14))); RoboCup.Geometry.Vector pos1 = new Vector(0, 0); RoboCup.Geometry.Vector pos2 = new Vector(0, 0); System.Drawing.Pen linePen = new System.Drawing.Pen(System.Drawing.Brushes.Black, xMod); for (int i = 0; i < DrawPlayerList.Count; i++) { Player p = DrawPlayerList[i]; pos1.X = (p.Position.X + 50) * xMod; pos2.X = (p.Position.X + 50) * xMod; pos1.Y = (p.Position.Y + 30) * yMod; pos2.Y = (p.Position.Y + 30) * yMod; pos1.X += (float)(Math.Cos(p.AngleBodyCommitted) * xMod * playerSize / 2); pos1.Y += (float)(Math.Sin(p.AngleBodyCommitted) * yMod * playerSize / 2); pos2.X -= (float)(Math.Cos(p.AngleBodyCommitted) * xMod * playerSize / 2); pos2.Y -= (float)(Math.Sin(p.AngleBodyCommitted) * yMod * playerSize / 2); g.FillEllipse(p.Side == "l"?System.Drawing.Brushes.Blue:p.Side == "r"?System.Drawing.Brushes.Red:System.Drawing.Brushes.Yellow, new System.Drawing.Rectangle(new System.Drawing.Point((int)Math.Round((p.Position.X + 50 - playerSize / 2) * xMod, (int)MidpointRounding.AwayFromZero), (int)Math.Round((p.Position.Y + 30 - playerSize / 2) * yMod, MidpointRounding.AwayFromZero)), new System.Drawing.Size((int)(playerSize * xMod), (int)(playerSize * yMod)))); g.DrawLine(linePen, pos1.X, pos1.Y, pos2.X, pos2.Y); } foreach (var b in Balls) { if (b != null) { g.FillEllipse(System.Drawing.Brushes.Gray, new System.Drawing.Rectangle(new System.Drawing.Point((int)Math.Round((b.Position.X + 50 - ballSize / 2) * xMod, (int)MidpointRounding.AwayFromZero), (int)Math.Round((b.Position.Y + 30 - ballSize / 2) * yMod, MidpointRounding.AwayFromZero)), new System.Drawing.Size((int)(ballSize * xMod), (int)(ballSize * yMod)))); } } foreach (Referee r in Referees) { r.doPaint(sender, e); } }
private void DrawField() { using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Model.fieldParam.CWidth, Model.fieldParam.CHeight)) { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) { g.FillRectangle(System.Drawing.Brushes.Gray, new System.Drawing.Rectangle(0, 0, Model.fieldParam.CWidth, Model.fieldParam.CHeight)); for (int i = 0; i < Model.fieldParam.Width; i++) { g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Silver), new System.Drawing.Point(i * Model.CellSize, 0), new System.Drawing.Point(i * Model.CellSize, Model.fieldParam.CHeight)); } for (int j = 0; j < Model.fieldParam.Height; j++) { g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Silver), new System.Drawing.Point(0, j * Model.CellSize), new System.Drawing.Point(Model.fieldParam.CWidth, j * Model.CellSize)); } foreach (Point?p in Model.cells) { if (p == null) { continue; } g.FillRectangle(new System.Drawing.SolidBrush(Model.CellFill), new System.Drawing.Rectangle((int)p.Value.X * Model.CellSize, (int)p.Value.Y * Model.CellSize, Model.CellSize, Model.CellSize)); g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Silver), new System.Drawing.Rectangle((int)p.Value.X * Model.CellSize, (int)p.Value.Y * Model.CellSize, Model.CellSize, Model.CellSize)); } BitmapImage bi = new BitmapImage(); using (MemoryStream memory = new MemoryStream()) { bmp.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); memory.Position = 0; bi.BeginInit(); bi.StreamSource = memory; bi.CacheOption = BitmapCacheOption.OnLoad; bi.EndInit(); } bi.Freeze(); Dispatcher.Invoke(() => { canvas.Source = bi; }); } } }
public void drawRoundRect(int x, int y, int width, int height, int d1, int d2) { int r1 = d1 / 2; int r2 = d2 / 2; System.Drawing.Pen pen = new System.Drawing.Pen(col); graph.DrawLine(pen, x + r1, y, x + width - r1, y); graph.DrawLine(pen, x + r1, y + height, x + width - r1, y + height); graph.DrawLine(pen, x, y + r2, x, y + height - r2); graph.DrawLine(pen, x + width, y + r2, x + width, y + height - r2); graph.DrawArc(pen, x, y, d1, d2, 180, 90); graph.DrawArc(pen, x + width - d1, y, d1, d2, 270, 90); graph.DrawArc(pen, x, y + height - d2, d1, d2, 90, 90); graph.DrawArc(pen, x + width - d1, y + height - d2, d1, d2, 0, 90); }
/// <summary> /// 绘制坐标系 /// </summary> /// <param name="g"></param> private void Draw_CoordinateSystem(System.Windows.Forms.PictureBox pictureBox, System.Drawing.Graphics g) { float x1, y1; var pa = new System.Drawing.PointF(); var pb = new System.Drawing.PointF(); // 绘制原点 { WorldToStreen(pictureBox, 0, 0, out x1, out y1); g.DrawEllipse(RedPen, (float)(x1 - PiexlPoint * 0.5), (float)(y1 - PiexlPoint * 0.5), PiexlPoint, PiexlPoint); g.FillEllipse(RedBrush, (float)(x1 - PiexlPoint * 0.5), (float)(y1 - PiexlPoint * 0.5), PiexlPoint, PiexlPoint); } // 绘制 X 轴 { pa.X = 0; pa.Y = 0; WorldToStreen(pictureBox, pa.X, pa.Y, out x1, out y1); pa.X = x1; pa.Y = y1; pb.X = 30; pb.Y = 0; WorldToStreen(pictureBox, pb.X, pb.Y, out x1, out y1); pb.X = x1; pb.Y = y1; g.DrawLine(RedPen, pa, pb); } // 绘制 Y 轴 { pa.X = 0; pa.Y = 0; WorldToStreen(pictureBox, pa.X, pa.Y, out x1, out y1); pa.X = x1; pa.Y = y1; pb.X = 0; pb.Y = 30; WorldToStreen(pictureBox, pb.X, pb.Y, out x1, out y1); pb.X = x1; pb.Y = y1; g.DrawLine(BluePen, pa, pb); } }
void PrintHeader(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, ref int yPosition) { int xPosition = bounds.Left; System.Drawing.StringFormat sf = new System.Drawing.StringFormat(); sf.Alignment = System.Drawing.StringAlignment.Center; g.DrawString(StringTable.Wishlist, printFontHeader, System.Drawing.Brushes.Black, new System.Drawing.RectangleF(xPosition, yPosition, bounds.Width, printFontHeader.Height), sf); sf.Alignment = System.Drawing.StringAlignment.Far; // Seitennummer, rechtsbündig sf.LineAlignment = System.Drawing.StringAlignment.Far; g.DrawString(string.Format("{0} {1}", StringTable.Page, currentPage), printFont, System.Drawing.Brushes.Black, new System.Drawing.RectangleF(xPosition, yPosition, bounds.Width, printFontHeader.Height), sf); sf.Alignment = System.Drawing.StringAlignment.Near; // Datum, linkgsbündig g.DrawString(DateTime.Now.ToShortDateString(), printFont, System.Drawing.Brushes.Black, new System.Drawing.RectangleF(xPosition, yPosition, bounds.Width, printFontHeader.Height), sf); yPosition += printFontHeader.Height + printFont.Height; int xSize = bounds.Width / 4; g.DrawString(StringTable.Artist, printFont, System.Drawing.Brushes.Black, new System.Drawing.PointF(xPosition, yPosition)); xPosition += xSize; g.DrawString(StringTable.Title, printFont, System.Drawing.Brushes.Black, new System.Drawing.PointF(xPosition, yPosition)); xPosition += xSize; g.DrawString(StringTable.From, printFont, System.Drawing.Brushes.Black, new System.Drawing.PointF(xPosition, yPosition)); xPosition += xSize; g.DrawString(StringTable.Comment, printFont, System.Drawing.Brushes.Black, new System.Drawing.PointF(xPosition, yPosition)); xPosition += xSize; yPosition += printFont.Height; g.DrawLine(System.Drawing.Pens.Black, bounds.Left, yPosition, bounds.Right, yPosition); yPosition += printFont.Height / 3; }
public static System.IO.MemoryStream GetValidateImg(out string code, string bgImg = "/Images/vcodebg.png") { code = GetValidateCode(); Random rnd = new Random(); System.Drawing.Bitmap img = new System.Drawing.Bitmap((int)Math.Ceiling((code.Length * 17.2)), 28); System.Drawing.Image bg = System.Drawing.Bitmap.FromFile(HttpContext.Current.Server.MapPath(bgImg)); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); System.Drawing.Font font = new System.Drawing.Font("Arial", 16, (System.Drawing.FontStyle.Regular | System.Drawing.FontStyle.Italic)); System.Drawing.Font fontbg = new System.Drawing.Font("Arial", 16, (System.Drawing.FontStyle.Regular | System.Drawing.FontStyle.Italic)); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, img.Width, img.Height), System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 1.2f, true); g.DrawImage(bg, 0, 0, new System.Drawing.Rectangle(rnd.Next(bg.Width - img.Width), rnd.Next(bg.Height - img.Height), img.Width, img.Height), System.Drawing.GraphicsUnit.Pixel); g.DrawString(code, fontbg, System.Drawing.Brushes.White, 0, 1); g.DrawString(code, font, System.Drawing.Brushes.Green, 0, 1);//字颜色 //画图片的背景噪音线 int x = img.Width; int y1 = rnd.Next(5, img.Height); int y2 = rnd.Next(5, img.Height); g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Green, 2), 1, y1, x - 2, y2); g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Transparent), 0, 10, img.Width - 1, img.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); return(ms); }
/// <summary> /// Draw line /// </summary> /// <param name="line"></param> /// <returns></returns> private string DrawLine(DocumentFormat.OpenXml.Vml.Line line) { string fileName = Path.Combine(imageDirectory, line.GetAttributes().Where(x => x.LocalName == "id").FirstOrDefault().Value + ".jpg"); string style = line.GetAttributes().Where(x => x.LocalName == "style").FirstOrDefault().Value; string position = GetValueOfProperty("position", style); int marginLeft = ConvertPointToPixel(GetValueOfProperty("margin-left", style)); int marginTop = ConvertPointToPixel(GetValueOfProperty("margin-top", style)); int width = (int)(ConvertToPixel(line.To.Value.Split(",".ToCharArray())[0]) - ConvertToPixel(line.From.Value.Split(",".ToCharArray())[0])); int height = (int)(ConvertToPixel(line.To.Value.Split(",".ToCharArray())[1]) - ConvertToPixel(line.From.Value.Split(",".ToCharArray())[1])); string strokeWeight = line.StrokeWeight != null ? line.StrokeWeight.Value : "3pt"; if (height == 0) { height = ConvertPointToPixel(strokeWeight); } System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height); using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(newBmp)) { System.Drawing.Pen pen = new System.Drawing.Pen(ConvertToColor(line.StrokeColor != null ? line.StrokeColor.Value : "black"), height); graphic.DrawLine(pen, 0, 0, newBmp.Width, newBmp.Height); } newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg); return(string.Format("<span style='position:{0};margin-left:{1}px;margin-top:{2}px;width:{3}px;height:{4}px'><img width=\"{3}\" height=\"{4}\" alt=\"{5}\" src=\"{6}\"/></span>", position, marginLeft, marginTop, width, height, Path.GetFileName(fileName), Util.GetRelativePath(fileName))); }
public static void Draw_bullet(int x1, int y1, int x2, int y2, System.Drawing.Pen pen) { if (Logic.fast_forward == false) { canvas.DrawLine(pen, x1, y1, x2, y2); } }
internal void Draw(Transformation trans, System.Drawing.Graphics g) { System.Drawing.Point p1 = trans.CalculatePixel(FromNode.Location); System.Drawing.Point p2 = trans.CalculatePixel(ToNode.Location); g.DrawLine(new System.Drawing.Pen(StyleManager.LineColor, 1), p1, p2); }
private void DrawingHistogramLine(System.Drawing.Bitmap Hist, int[] gray, System.Drawing.Color color) { try { System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(Hist); System.Drawing.PointF org = new System.Drawing.PointF(5, Hist.Height - 5); System.Drawing.PointF p_p = new System.Drawing.PointF(org.X, org.Y - 1); System.Drawing.PointF p_c = new System.Drawing.PointF(0, 0); System.Drawing.Pen mypen = new System.Drawing.Pen(color, 3); int MassGray = gray.Max(), length = gray.Length > 256 ? 256 : gray.Length; int interval = Convert.ToInt32(Math.Floor(Convert.ToSingle(Hist.Width) / 256)); for (int i = 0; i < length; i++) { p_c = new System.Drawing.PointF(org.X + (i * interval), (org.Y - 1) * (1 - ((Convert.ToSingle(gray[i]) / Convert.ToSingle(MassGray)) * Convert.ToSingle(0.9)))); g.DrawLine(mypen, p_p, p_c); p_p = p_c; } } catch (SystemException ex) { System.Windows.Forms.MessageBox.Show("In ImageProc.DrawingHistogramLine: " + ex.ToString()); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("In ImageProc.DrawingHistogramLine: " + ex.ToString()); } finally { GC.Collect(); } }
/// <summary> /// Draws all lines in the array using pen on graphics /// </summary> public static void DrawLinesFromArray(System.Drawing.Graphics graphics, System.Drawing.Pen pen, Line[] lines) { foreach (Line line in lines) { graphics.DrawLine(pen, line.StartPoint, line.EndPoint); } }
public override void Draw(Graphics g) { base.Draw(g); if (Annotation.Polygon.Length == 0) return; var pt = this.Annotation.Polygon .Select(x => Element.ToPictureBoxCoordinate(x.ToPt()).ToPt()) .Select(x => x.Round()) .First(); //pt = Element.ToPictureBoxCoordinate(new Point(475, 306).ToPt()).ToPt().Round(); g.DrawRectangle(Pen, new System.Drawing.Rectangle(pt.X - RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, RECT_SIZE, RECT_SIZE)); g.DrawLine(Pen, pt.X - RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, pt.X + RECT_SIZE / 2, pt.Y + RECT_SIZE / 2); // \ g.DrawLine(Pen, pt.X + RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, pt.X - RECT_SIZE / 2, pt.Y + RECT_SIZE / 2); // / }
private static System.Windows.Forms.PictureBox GetDrawingBox() { var box = new System.Windows.Forms.PictureBox(); var pen = new System.Drawing.Pen(System.Drawing.Color.White, System.Windows.Forms.Control.DefaultFont.Height * 2.2f); pen.StartCap = pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; System.Drawing.Graphics graphics = null; box.SizeChanged += delegate { if (box.Width == 0 || box.Height == 0) { return; } var oldImage = box.Image; box.Image = new System.Drawing.Bitmap(box.Width, box.Height); oldImage?.Dispose(); graphics = System.Drawing.Graphics.FromImage(box.Image); graphics.FillRectangle(System.Drawing.Brushes.Black, 0, 0, box.Height, box.Height); }; var lastPos = System.Drawing.Point.Empty; box.MouseMove += (sender, args) => { if (args.Button == System.Windows.Forms.MouseButtons.Left) { graphics.DrawLine(pen, lastPos, args.Location); box.Invalidate(); } lastPos = args.Location; }; return(box); }
public override void DrawLine(CommonGui.Drawing.Pen pen, Chaos.Util.Mathematics.Vector2f p1, Chaos.Util.Mathematics.Vector2f p2) { using (System.Drawing.Pen pen2 = CreatePen(pen)) { InternalGraphics.DrawLine(pen2, p1.Convert(), p2.Convert()); } }