public override void Draw(System.Drawing.RectangleF dirtyRect) { var g = new Graphics(); // NSView does not have a background color so we just use Clear to white here g.Clear(Color.White); //RectangleF ClientRectangle = this.Bounds; RectangleF ClientRectangle = dirtyRect; // Calculate the location and size of the drawing area // within which we want to draw the graphics: Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y, (int)ClientRectangle.Width, (int)ClientRectangle.Height); drawingRectangle = new Rectangle(rect.Location, rect.Size); drawingRectangle.Inflate(-offset, -offset); //Draw ClientRectangle and drawingRectangle using Pen: g.DrawRectangle(Pens.Red, rect); g.DrawRectangle(Pens.Black, drawingRectangle); // Draw a line from point (3,2) to Point (6, 7) // using the Pen with a width of 3 pixels: Pen aPen = new Pen(Color.Green, 3); g.DrawLine(aPen, Point2D(new PointF(3, 2)), Point2D(new PointF(6, 7))); g.PageUnit = GraphicsUnit.Inch; ClientRectangle = new RectangleF(0.5f,0.5f, 1.5f, 1.5f); aPen.Width = 1 / g.DpiX; g.DrawRectangle(aPen, ClientRectangle); aPen.Dispose(); g.Dispose(); }
public InterestPointDrawer(Bitmap background, SRegion[] regions) : base(background, regions) { Color c = Color.FromArgb(125, Color.Red); pen = new Pen(c); brush = new SolidBrush(c); }
public void Constructor_Color_Float () { using (Pen p = new Pen (Color.Red, 2.5f)) { Assert.AreEqual (2.5f, p.Width, "Width"); Check (p); } }
public static void DrawRoundRectangle(Graphics g, Pen pen, Rectangle rect, int cornerRadius) { using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius)) { g.DrawPath(pen, path); } }
public RectangleTransparent() { clearPen = new Pen(Color.FromArgb(1, 0, 0, 0)); borderDotPen = new Pen(Color.Black, 1); borderDotPen2 = new Pen(Color.White, 1); borderDotPen2.DashPattern = new float[] { 5, 5 }; penTimer = Stopwatch.StartNew(); ScreenRectangle = CaptureHelpers.GetScreenBounds(); surface = new Bitmap(ScreenRectangle.Width, ScreenRectangle.Height); gSurface = Graphics.FromImage(surface); gSurface.InterpolationMode = InterpolationMode.NearestNeighbor; gSurface.SmoothingMode = SmoothingMode.HighSpeed; gSurface.CompositingMode = CompositingMode.SourceCopy; gSurface.CompositingQuality = CompositingQuality.HighSpeed; gSurface.Clear(Color.FromArgb(1, 0, 0, 0)); StartPosition = FormStartPosition.Manual; Bounds = ScreenRectangle; Text = "ShareX - " + Resources.RectangleTransparent_RectangleTransparent_Rectangle_capture_transparent; Shown += RectangleLight_Shown; KeyUp += RectangleLight_KeyUp; MouseDown += RectangleLight_MouseDown; MouseUp += RectangleLight_MouseUp; using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } timer = new Timer { Interval = 10 }; timer.Tick += timer_Tick; timer.Start(); }
public Circle(float x, float y, float r, Color color) { this.x = x; this.y = y; this.radius = r; this.p = new System.Drawing.Pen(color, 3.5f); }
public void Constructor_Color () { using (Pen p = new Pen (Color.Red)) { Assert.AreEqual (1, p.Width, "Width"); Check (p); } }
public void DrawPipeLine(Graphics g,GSOPipeLineStyle3D pipeLineStyle) { Pen newPen = new Pen(pipeLineStyle.LineColor, 1.0f); int nEllipseHeight = (int)(Height * 0.3); int nEllipseWidth = nEllipseHeight/2; int nStartX = (int)(Width*0.1); int nHalfHeight=Height/2; int nBodyStartX=nStartX+nEllipseWidth/2; Rectangle rcEllipse = new Rectangle(nStartX, nHalfHeight - nEllipseHeight / 2, nEllipseWidth, nEllipseHeight); Rectangle rcTailEllipse = new Rectangle(this.Width - nStartX - nEllipseWidth, nHalfHeight - nEllipseHeight / 2, nEllipseWidth, nEllipseHeight); Rectangle rcFill = new Rectangle(nBodyStartX, rcEllipse.Top, Width - 2*nBodyStartX+nEllipseWidth/2, nEllipseHeight); Color FColor = pipeLineStyle.LineColor; Color TColor = Color.FromArgb(255, 255, 255); Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.BackwardDiagonal); g.FillRectangle(b, rcFill); g.DrawEllipse(newPen, rcEllipse); g.DrawEllipse(newPen, rcTailEllipse); g.DrawLine(newPen, nBodyStartX, rcEllipse.Top, Width - nBodyStartX, rcEllipse.Top); g.DrawLine(newPen, nBodyStartX, rcEllipse.Bottom, Width - nBodyStartX, rcEllipse.Bottom); }
public Surface() { ScreenRectangle = CaptureHelpers.GetScreenBounds(); ScreenRectangle0Based = CaptureHelpers.ScreenToClient(ScreenRectangle); InitializeComponent(); using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } DrawableObjects = new List<DrawableObject>(); Config = new SurfaceOptions(); timerStart = new Stopwatch(); timerFPS = new Stopwatch(); borderPen = new Pen(Color.Black); borderDotPen = new Pen(Color.White); borderDotPen.DashPattern = new float[] { 5, 5 }; nodeBackgroundBrush = new SolidBrush(Color.White); textFont = new Font("Verdana", 16, FontStyle.Bold); infoFont = new Font("Verdana", 9); textBackgroundBrush = new SolidBrush(Color.FromArgb(75, Color.Black)); textBackgroundPenWhite = new Pen(Color.FromArgb(50, Color.White)); textBackgroundPenBlack = new Pen(Color.FromArgb(150, Color.Black)); markerPen = new Pen(Color.FromArgb(200, Color.Red)) { DashStyle = DashStyle.Dash }; }
public void Draw(Graphics gr, Pen pen, Brush backgroundBrush, Pen forePen) { //draw minus gr.FillRectangle(backgroundBrush, rectangle); gr.DrawRectangle(pen, rectangle); gr.DrawLine(forePen, rectangle.Left + 2, rectangle.Top + rectangle.Height / 2, rectangle.Right - 2, rectangle.Top + rectangle.Height / 2); }
public Pen GetPen() { Random r = new Random(); Color color = Color.FromArgb(255, r.Next(255), r.Next(255), r.Next(255)); Pen pen = new Pen(color); return pen; }
public void DrawPath(Graphics g, Pen p) { if (m_points != null) { g.DrawLines(p, m_points); } }
public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners) { if (appointment == null) throw new ArgumentNullException("appointment"); if (g == null) throw new ArgumentNullException("g"); if (rect.Width != 0 && rect.Height != 0) using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; if ((appointment.Locked) && isSelected) { // Draw back using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color)) g.FillRectangle(m_Brush, rect); } else { // Draw back using (SolidBrush m_Brush = new SolidBrush(appointment.Color)) g.FillRectangle(m_Brush, rect); } if (isSelected) { using (Pen m_Pen = new Pen(appointment.BorderColor, 4)) g.DrawRectangle(m_Pen, rect); Rectangle m_BorderRectangle = rect; m_BorderRectangle.Inflate(2, 2); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); m_BorderRectangle.Inflate(-4, -4); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); } else { // Draw gripper gripRect.Width += 1; using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor)) g.FillRectangle(m_Brush, gripRect); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, rect); } rect.X += gripRect.Width; g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format); } }
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 OnPaint(PaintEventArgs e) { int width = this.Width; int height = this.Height; int banJing = 10; int ellipseX = (width - banJing * 4) / 2; int ellipseY = (height - banJing * 4) / 2; int fontX = (width - banJing * 8) / 2; int fontY = height / 2; //计算中点:width/2,height/2 Graphics g = e.Graphics; Pen pn = new Pen(Color.Green, 10); Rectangle rect = new Rectangle(ellipseX, ellipseY, 10, 10); g.DrawEllipse(pn, rect); Font fnt = new Font("宋体", 16); g.DrawString("你好", fnt, new SolidBrush(Color.Red), fontX, fontY); int n = 10; double average = 360 / n; int size = 100; for (int i = 1; i < n + 1; i++) { int ellipseX1 = ellipseX + (int)(Math.Cos(((average * i * Math.PI) / 180.0)) * size); int ellipseY1 = ellipseY + (int)(Math.Sin(((average * i * Math.PI) / 180.0)) * size); Pen pn1 = new Pen(Color.Green, 10); Rectangle rect1 = new Rectangle(ellipseX1, ellipseY1, 10, 10); g.DrawEllipse(pn1, rect1); //Console.WriteLine("average=" + average + " " + "average * i=" + average * i); //Console.WriteLine("Math.Cos(average * i):" + Math.Cos(average * i) + " " + "Math.Sin(average * i):" + Math.Sin(average * i)); } int m = 10; average = 360 / m; size = 150; for (int i = 1; i < n + 1; i++) { int ellipseX1 = ellipseX + (int)(Math.Cos(((average * i * Math.PI) / 180.0)) * size); int ellipseY1 = ellipseY + (int)(Math.Sin(((average * i * Math.PI) / 180.0)) * size); Pen pn1 = new Pen(Color.Green, 10); Rectangle rect1 = new Rectangle(ellipseX1, ellipseY1, 10, 10); g.DrawEllipse(pn1, rect1); //Console.WriteLine("average=" + average + " " + "average * i=" + average * i); //Console.WriteLine("Math.Cos(average * i):" + Math.Cos(average * i) + " " + "Math.Sin(average * i):" + Math.Sin(average * i)); } int p = 10; average = 360 / p; size = 200; for (int i = 1; i < n + 1; i++) { int ellipseX1 = ellipseX + (int)(Math.Cos(((average * i * Math.PI) / 180.0)) * size); int ellipseY1 = ellipseY + (int)(Math.Sin(((average * i * Math.PI) / 180.0)) * size); Pen pn1 = new Pen(Color.Green, 10); Rectangle rect1 = new Rectangle(ellipseX1, ellipseY1, 10, 10); g.DrawEllipse(pn1, rect1); //Console.WriteLine("average=" + average + " " + "average * i=" + average * i); //Console.WriteLine("Math.Cos(average * i):" + Math.Cos(average * i) + " " + "Math.Sin(average * i):" + Math.Sin(average * i)); } }
public override void Draw(Graphics graphics, RenderMode rm) { int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); bool shadow = GetFieldValueAsBool(FieldType.SHADOW); bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor)); if (lineVisible) { graphics.SmoothingMode = SmoothingMode.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.None; //draw shadow first if (shadow) { int basealpha = 100; int alpha = basealpha; int steps = 5; int currentStep = lineVisible ? 1 : 0; while (currentStep <= steps) { using (Pen shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) { Rectangle shadowRect = GuiRectangle.GetGuiRectangle(Left + currentStep, Top + currentStep, Width, Height); graphics.DrawRectangle(shadowPen, shadowRect); currentStep++; alpha = alpha - (basealpha / steps); } } } Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); if (lineThickness > 0) { using (Pen pen = new Pen(lineColor, lineThickness)) { graphics.DrawRectangle(pen, rect); } } } }
public Lente01() { InitializeComponent(); lente = new Lente(); // Crea nuovi oggetti sorgente = new SorgenteOttica(); finestra = new Finestra(); nomefile = "-"; displayList = new DisplayList(); singolo = new Ambiente(); completo = new Ambiente(); ambienteAttivo = singolo; penne = new Pen[4]; penne[0] = new Pen(Color.Blue,2); penne[1] = new Pen(Color.Red,1); penne[2] = new Pen(Color.Green,1); penne[3] = new Pen(Color.Gray,1); angolo = 0; this.gradiprimi.Value = angolo; percentodiam = 110; this.percdiam.Value = percentodiam; RidimensionaFinestra(); // Richiede primo ricalcolo della finestra }
private void button1_Click(object sender, EventArgs e) { // dibujando rectnagulos Graphics papel = pictureBox1.CreateGraphics(); Pen lapiz = new Pen(Color.Black); papel.DrawRectangle(lapiz, 0, 0, 100, 40); // dibujar lines papel.DrawLine(lapiz, 20,10, 100,200); // dibujar ovalos papel.DrawEllipse(lapiz, 100, 100, 100, 300); /// dibujando formas rellenas /// se debe usar una brocha no un lapiz Brush brocha = new SolidBrush(Color.Red); papel.FillRectangle(brocha, 30, 70, 60, 90); papel.FillEllipse(brocha, 80, 30, 20, 50); // introducir una imagen puede ser, jpge, gif, bmp etc. Bitmap imagenCargada = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg"); papel.DrawImage(imagenCargada, 50, 50, 200, 200); }
static void DrawGraph(object sender, PaintEventArgs args) { if (map == null) return; var g = args.Graphics; var W = pointsPanel.ClientSize.Width - 20; var H = pointsPanel.ClientSize.Height - 20; g.Clear(Color.White); g.TranslateTransform(10, 10); var pen=new Pen(Color.FromArgb(100,Color.LightGray)); foreach (var e in map) { if (e.MapX != task.NetworkWidth - 1) g.DrawLine(pen, W * e.X, H * e.Y, W * map[e.MapX + 1, e.MapY].X, H * map[e.MapX + 1, e.MapY].Y); if (e.MapY != task.NetworkHeight - 1) g.DrawLine(pen, W * e.X, H * e.Y, W * map[e.MapX, e.MapY + 1].X, H * map[e.MapX, e.MapY + 1].Y); } foreach(var e in map) { g.FillEllipse(GetBrush(e), e.X*W-3, e.Y*W-3, 6, 6); } }
public Player() { _pen = new Pen(Ext.ColorFromHsv(120, 0.75, 0.75)); _brush = new SolidBrush(_pen.Color); _field = EntitiesOfType<Field>().Single(); Respawn(); }
public Circle(float x, float y, float r) { this.x = x; this.y = y; this.radius = r; this.p = new System.Drawing.Pen(Color.Black, 3.0f); }
private void dataSelectionList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { Color color; switch (e.ColumnIndex) { case 2: color = Color.FromArgb(int.Parse(e.SubItem.Text)); Rectangle rect = e.Bounds; rect.Inflate(-4, -2); using (SolidBrush brush = new SolidBrush(color)) { e.Graphics.FillRectangle(brush, rect); e.Graphics.DrawRectangle(Pens.Black, rect); } break; case 3: float x1 = e.SubItem.Bounds.X; float x2 = e.SubItem.Bounds.X + e.SubItem.Bounds.Width; float y = e.SubItem.Bounds.Y + e.SubItem.Bounds.Height / 2; color = Color.FromArgb(int.Parse(e.Item.SubItems[2].Text)); float thickness = float.Parse(e.Item.SubItems[1].Text); using (Pen pen = new Pen(color, thickness)) { e.Graphics.DrawLine(pen, x1, y, x2, y); } break; default: e.DrawDefault = true; break; } }
public Surface(Image backgroundImage = null) { ScreenRectangle = CaptureHelpers.GetScreenBounds(); ScreenRectangle0Based = CaptureHelpers.ScreenToClient(ScreenRectangle); InitializeComponent(); using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } if (backgroundImage != null) { SurfaceImage = backgroundImage; Prepare(); } DrawableObjects = new List<DrawableObject>(); Config = new SurfaceOptions(); timer = new Stopwatch(); borderPen = new Pen(Color.Black); borderDotPen = new Pen(Color.Black, 1); borderDotPen2 = new Pen(Color.White, 1); borderDotPen2.DashPattern = new float[] { 5, 5 }; nodeBackgroundBrush = new SolidBrush(Color.White); textFont = new Font("Arial", 17, FontStyle.Bold); }
public static void DrawRoundedRectangle(this Graphics g, Pen pen, RectangleF rect, float cornerRadius) { using(var gp = GraphicsUtility.GetRoundedRectangle(rect, cornerRadius)) { g.DrawPath(pen, gp); } }
public override void Nacrtaj(Graphics g) { using (Pen pero = new Pen(Color.Blue)) { g.DrawRectangle(pero, x, y, širina, visina); } }
private void pnl_painter_MouseMove(object sender, MouseEventArgs e) { Brush brush1 = new SolidBrush(Color.Black); if (rdo_black.Checked) color = "black"; else if (rdo_blue.Checked) color = "blue"; else if (rdo_red.Checked) color = "red"; switch (color) { case "black": brush1 = new SolidBrush(Color.Black); break; case "blue": brush1 = new SolidBrush(Color.Blue); break; case "red": brush1 = new SolidBrush(Color.Red); break; } if (rdo_small.Checked) size = 4; else if (rdo_middle.Checked) size = 8; else if (rdo_large.Checked) size = 12; x2 = e.X; y2 = e.Y; Pen pen1 = new Pen(brush1, size); pen1.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Flat); //pen1.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; if (shouldPaint) { Graphics graphics = pnl_painter.CreateGraphics(); //graphics.FillEllipse(brush1, e.X, e.Y, size, size); graphics.DrawLine(pen1, x1, y1, x2, y2); graphics.Dispose(); } x1 = e.X; y1 = e.Y; }
public void UpdateImage() { if (!showCheckBox.Checked) return; Graphics g = pictureBox.CreateGraphics(); int x; int y; Pen activeColumnPen = new Pen(new SolidBrush(Color.Gray)); Pen inactiveColumnPen = new Pen(new SolidBrush(Color.White)); Brush activeColumnBrush = new SolidBrush(Color.Gray); Brush inactiveColumnBrush = new SolidBrush(Color.White); for (int ix = 0; ix < _inputs.Width; ix++) { for (int iy = 0; iy < _inputs.Height; iy++) { x = (int)(ix * 5); y = (int)(iy * 5); if (_inputs[ix, iy].GetActive(0)) g.FillRectangle(activeColumnBrush, x, y, cellWidth, cellHeight); else g.FillRectangle(inactiveColumnBrush, x, y, cellWidth, cellHeight); } } }
public AccountGridButton() { InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); fontLarge = FONT_LARGE; fontSmall = FONT_SMALL; brush = new SolidBrush(Color.LightGray); pen = new Pen(brush); _AccountName = "Example"; _DisplayName = "*****@*****.**"; _LastUsed = DateTime.MinValue; _ShowAccount = true; using (var g = this.CreateGraphics()) { ResizeLabels(g); } this.Disposed += AccountGridButton_Disposed; }
protected override void OnPaint(PaintEventArgs pe) { // Calling the base class OnPaint base.OnPaint(pe); // Pre Display computings Point ptRotation = new Point(150, 150); Point ptimgNeedle = new Point(136,39); bmpCadran.MakeTransparent(Color.Yellow); bmpNeedle.MakeTransparent(Color.Yellow); double alphaNeedle = InterpolPhyToAngle(airSpeed,0,80,180,468); float scale = (float)this.Width / bmpCadran.Width; // diplay mask Pen maskPen = new Pen(this.BackColor, 30 * scale); pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpCadran.Width * scale, bmpCadran.Height * scale); // display cadran pe.Graphics.DrawImage(bmpCadran, 0, 0, (float)(bmpCadran.Width * scale), (float)(bmpCadran.Height * scale)); // display small needle RotateImage(pe, bmpNeedle, alphaNeedle, ptimgNeedle, ptRotation, scale); }
public void DrawCross(Panel panel) { Graphics g = panel.CreateGraphics(); Pen _pen = new Pen(Color.Black, _linewidth); g.DrawLine(_pen, new Point(_innerMargin, _innerMargin), new Point(_square - _innerMargin, _square - _innerMargin)); g.DrawLine(_pen, new Point(_innerMargin, _square - _innerMargin), new Point(_square - _innerMargin, _innerMargin)); }
public override void DrawArmyXY(PosXY pos, Terrain terra) { //set color var c = Color.White; if (terra.FriendFoe[pos.PosX, pos.PosY] != (int)FriendFoeKind.friend) { c = Color.Orange; } var pen = new System.Drawing.Pen(c); var x = pos.PosX * glb_settings.get_map_box_size(); var y = pos.PosY * glb_settings.get_map_box_size(); var army_type = terra.ArmyUnits[pos]; switch ((int)army_type.ArmyType) { case (int)ArmyType.light_infantry: //infantry light DrawInfantry(pen, x, y); break; case (int)ArmyType.heavy_infantry: //infantry heavy DrawInfantry(pen, x, y); break; case (int)ArmyType.light_cavalry: //cavalry light DrawCavalry(pen, x, y); break; case (int)ArmyType.heavy_cavalry: //cavalry light DrawCavalry(pen, x, y); break; case (int)ArmyType.light_artillery: //cavalry light DrawArtillery(pen, x, y); break; case (int)ArmyType.heavy_artillery: //cavalry light DrawArtillery(pen, x, y); break; case (int)ArmyType.logistic: //cavalry light DrawLogistic(pen, x, y); break; case (int)ArmyType.recruitment: //cavalry light DrawRecruitment(pen, x, y); break; default: break; } //heavy bars added if ((int)army_type.ArmyType == (int)ArmyType.heavy_infantry || (int)army_type.ArmyType == (int)ArmyType.heavy_cavalry || (int)army_type.ArmyType == (int)ArmyType.heavy_artillery) { graph.DrawLine(pen, x + 2, y + 2, x + 10, y + 2); } }
public void GenerateBitmap() { int i = 0; while (true) { if (i == 20) { break; } Bitmap Btmap = new Bitmap(640, 480); string Dimensions = "X="; //Clear surface for (int y = 0; y < 480; y++) { for (int x = 0; x < 640; x++) { Btmap.SetPixel(x, y, System.Drawing.Color.White); } } using (Graphics g = Graphics.FromImage(Btmap)) { Random rng = new Random(); Rectangle rect = new Rectangle(); //Randomize rectangle position and size rect.X = rng.Next(20, 600); rect.Y = rng.Next(20, 440); Dimensions += rect.X; Dimensions += " Y="; Dimensions += rect.Y; rect.Width = rng.Next(20, 640 - rect.X); rect.Height = rng.Next(20, 480 - rect.Y); //Pen and brush System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 5); System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); g.DrawRectangle(pen, rect); g.FillRectangle(brush, rect); //Randomize elipse position and size rect.X = rng.Next(20, 600); rect.Y = rng.Next(20, 440); rect.Width = rng.Next(20, 640 - rect.X); rect.Height = rng.Next(20, 480 - rect.Y); pen = new System.Drawing.Pen(System.Drawing.Color.Blue, 5); brush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); g.DrawEllipse(pen, rect); g.FillEllipse(brush, rect); } var handle = Btmap.GetHbitmap(); try { if (Application.Current != null) { Application.Current.Dispatcher.BeginInvoke((Action) delegate() { this.Rect = Dimensions; this.Bitmap = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); }); } else { break; } Thread.Sleep(500); } finally { DeleteObject(handle); i++; } } }
/// <summary> /// Renders a LineString to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="line">LineString to render</param> /// <param name="pen">Pen style used for rendering</param> /// <param name="map">Map reference</param> public static void DrawBezierString(System.Drawing.Graphics g, ILineString line, System.Drawing.Pen pen, IMap map) { if (line.Coordinates.Length > 1) { var gp = new GraphicsPath(); var points = Transform.TransformToImage(line, map); if (points.Length > 0) { gp.AddBeziers(points); g.DrawPath(pen, gp); } } }
public void DrawLine(System.Drawing.Pen pen, int x1, int y1, int x2, int y2) { //pen.Color = color; gr.DrawLine(pen, x1, y1, x2, y2); }
/// <summary> /// Draw the footprint line in GDI. /// </summary> /// <param name="graphics"></param> /// <param name="pen"></param> public void Draw(System.Drawing.Graphics graphics, System.Drawing.Pen pen) { Curve curve = m_curve.GeometryCurve; DrawCurve(graphics, pen, curve); }
private void editor_animations_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!TabEditor.IsSelected || editor_animations.SelectedIndex == -1) { return; } currently_editing_animation = sprite.AnimationModule.Animations[(string)editor_animations.SelectedItem]; currently_editing_animation_row = editor_animations.SelectedIndex; var bitmap = new System.Drawing.Bitmap(sprite.Texture.Bitmap); //Clone it, we don't want to write on our texture var bluePen = new System.Drawing.Pen(System.Drawing.Color.Aqua, 2); var moduleSprite = currently_editing_animation.Owner as ModuleSprite; if (moduleSprite != null) { var ownerModule = moduleSprite.GetFirstModule <AnimationModule>(); int x = 0; int y = 0; for (int i = 0; i < currently_editing_animation.Row; i++) { y += ownerModule.Animations[i].Height; } float width = currently_editing_animation.Width * currently_editing_animation.Frames; float height = y + currently_editing_animation.Height; using (var graphics = Graphics.FromImage(bitmap)) { graphics.DrawLine(bluePen, x, y, width, y); graphics.DrawLine(bluePen, width, y, width, height); graphics.DrawLine(bluePen, x, height, width, height); graphics.DrawLine(bluePen, x, y, x, height); } ImageSource @new = ToBitmapSource(bitmap); bitmap.Dispose(); sheet_editor.Source = @new; //Create frames Frames.Children.Clear(); bitmap = new System.Drawing.Bitmap(sprite.Texture.Bitmap); //Clone it, we don't want to write on our texture for (int i = 0; i < currently_editing_animation.Frames; i++) { var result = new Bitmap(currently_editing_animation.Width, currently_editing_animation.Height); x = currently_editing_animation.Width * i; y = 0; for (int z = 0; z < currently_editing_animation.Row; z++) { y += ownerModule.Animations[i].Height; } width = currently_editing_animation.Width; height = currently_editing_animation.Height; using (var g = Graphics.FromImage(result)) { g.DrawImage(bitmap, new RectangleF(0f, 0f, width, height), new RectangleF(x, y, width, height), GraphicsUnit.Pixel); } var btn = new Button(); btn.Name = "b" + i; btn.Width = 32; btn.ContextMenu = FindResource("cmButton") as ContextMenu; if (btn.ContextMenu != null) { btn.ContextMenu.PlacementTarget = btn; btn.Click += delegate { try { selectedIndex = int.Parse(btn.Name.Substring(1)); btn.ContextMenu.IsOpen = !btn.ContextMenu.IsOpen; } catch { } }; } var img = new System.Windows.Controls.Image { Source = ToBitmapSource(result) }; btn.Content = img; result.Dispose(); Frames.Children.Add(btn); } } bitmap.Dispose(); }
public BarRenderer(System.Drawing.Pen pen, Color start, Color end) : this() { this.Pen = pen; this.SetGradient(start, end); }
private void redraw_OLD() { Graphics g = this.CreateGraphics(); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //Do Double Buffering Graphics offScreenDC; //offScreenBmp = new Bitmap(this.Width, this.Height); // offScreenDC = Graphics.FromImage(offScreenBmp); offScreenDC.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; offScreenDC.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; offScreenDC.Clear(this.BackColor); if (this.BackgroundImage != null) { offScreenDC.DrawImage(this.BackgroundImage, 0, 0); } // Visualizzazione Griglia if (this.gridSize > 0) { System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.LightGray); int nX = this.Width / this.gridSize; for (int i = 0; i <= nX; i++) { offScreenDC.DrawLine(myPen, i * this.gridSize, 0, i * this.gridSize, this.Height); } int nY = this.Height / this.gridSize; for (int i = 0; i <= nY; i++) { offScreenDC.DrawLine(myPen, 0, i * this.gridSize, this.Width, i * this.gridSize); } myPen.Dispose(); } // Disegna tutti gli oggetti s.Draw(offScreenDC, 0, 0, 1); //Draw Red creation Rect/Line if (this.MouseSx & this.Status == "drawrect") { System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red, 1.5f); myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; myPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; //myPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; if (this.Option == "LI") { offScreenDC.DrawLine(myPen, startX, startY, tempX, tempY); } else { offScreenDC.DrawRectangle(myPen, new Rectangle(this.startX, this.startY, tempX - this.startX, tempY - this.startY)); } myPen.Dispose(); } //Draw selection Rect if (this.MouseSx & this.Status == "selrect") { System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Green, 1.5f); myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; offScreenDC.DrawRectangle(myPen, new Rectangle(this.startX, this.startY, tempX - this.startX, tempY - this.startY)); myPen.Dispose(); } g.DrawImageUnscaled(offScreenBmp, 0, 0); offScreenDC.Dispose(); g.Dispose(); }
/// <summary> /// 3.算法画箭头 /// </summary> /// <param name="p1">上一图片左上角坐标</param> /// <param name="p2">下一图片左上角坐标</param> /// <param name="width">图片宽度</param> /// <param name="height">图片高度</param> /// <param name="pen">画笔</param> private void MakeArrowByCal(System.Drawing.Point p1, System.Drawing.Point p2, int width, int height, Pen pen) { //以下微调 p1.Y -= 125; p2.Y -= 125; p1.X += 2; p2.X += 2; var pstart = new System.Drawing.Point(); var pend = new System.Drawing.Point(); if (p1.X == p2.X)//向下 { pstart.X = p1.X + width / 2; pstart.Y = p1.Y + height; pend.X = p2.X + width / 2; pend.Y = p2.Y; //以下微调 pend.Y -= 30; } else if (p1.X < p2.X)//向右 { pstart.X = p1.X + width; pstart.Y = p1.Y + height / 2; pend.X = p2.X; pend.Y = p2.Y + height / 2; } else if (p1.X > p2.X)//向左 { pstart.X = p1.X; pstart.Y = p1.Y + height / 2; pend.X = p2.X + width; pend.Y = p2.Y + height / 2; } //画箭头,只对不封闭曲线有用 pen.DashStyle = DashStyle.Solid; pen.EndCap = LineCap.ArrowAnchor; g.DrawLine(pen, pstart, pend);//x1,y1,x2,y2 }
/// <summary> /// 生成图片验证码 /// </summary> /// <param name="nLen">验证码的长度</param> /// <param name="strKey">输出参数,验证码的内容</param> /// <param name="PureBlackBackGround">是否黑白色</param> /// <returns>图片字节流</returns> private byte[] GenerateVerifyImage(int keyLength, ref string imageCodeKey, bool pureBlackBackGround, bool drawDisturbLine) { int bmpWidth = 26 * keyLength + 8; int bmpHeight = 20; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpWidth, bmpHeight); // 1. 生成随机背景颜色 int red, green, blue; // 背景的三元色 System.Random rd = new Random((int)System.DateTime.Now.Ticks); if (!pureBlackBackGround) { red = rd.Next(255) % 128 + 128; green = rd.Next(255) % 128 + 128; blue = rd.Next(255) % 128 + 128; } else { red = 255; green = 255; blue = 255; } // 2. 填充位图背景 System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp); graph.FillRectangle(new SolidBrush(System.Drawing.Color.FromArgb(red, green, blue)) , 0 , 0 , bmpWidth , bmpHeight); // 3. 绘制干扰线条,采用比背景略深一些的颜色 if (drawDisturbLine) { int lines = 3; System.Drawing.Pen pen; if (!pureBlackBackGround) { pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(red - 17, green - 17, blue - 17), 1); } else { pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(12, 12, 12), 1); } for (int a = 0; a < lines; a++) { int x1 = rd.Next() % bmpWidth; int y1 = rd.Next() % bmpHeight; int x2 = rd.Next() % bmpWidth; int y2 = rd.Next() % bmpHeight; graph.DrawLine(pen, x1, y1, x2, y2); } } // 采用的字符集,可以随即拓展,并可以控制字符出现的几率 string codeScop = "ABCDEFGHJKLMNPRSTUVWXYZ23456789"; // 4. 循环取得字符,并绘制 string result = ""; for (int i = 0; i < keyLength; i++) { int coordinateX = (i * 26 + rd.Next(3)); int coordinateY = rd.Next(2) + 1; // 确定字体 System.Drawing.Font font = new System.Drawing.Font("Courier New", 13 + rd.Next() % 4, System.Drawing.FontStyle.Bold); char currentChar = codeScop[rd.Next(codeScop.Length)]; // 随机获取字符 result += currentChar.ToString(); // 绘制字符 if (!pureBlackBackGround) { graph.DrawString(currentChar.ToString(), font, new SolidBrush(System.Drawing.Color.FromArgb(red - 60 + coordinateY * 3, green - 60 + coordinateY * 3, blue - 40 + coordinateY * 3)), coordinateX, coordinateY); } else { graph.DrawString(currentChar.ToString(), font, new SolidBrush(System.Drawing.Color.FromArgb(0, 0, 0)), coordinateX, coordinateY); } } // 5. 输出字节流 System.IO.MemoryStream bstream = new System.IO.MemoryStream(); //bmp = TwistImage(bmp, true, 2.0, 2.0); bmp.Save(bstream, System.Drawing.Imaging.ImageFormat.Jpeg); bmp.Dispose(); graph.Dispose(); imageCodeKey = result; byte[] byteReturn = bstream.ToArray(); bstream.Close(); return(byteReturn); }
/// <summary> /// Renders a LineString to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="line">LineString to render</param> /// <param name="pen">Pen style used for rendering</param> /// <param name="map">Map reference</param> public static void DrawLineString(System.Drawing.Graphics g, ILineString line, System.Drawing.Pen pen, IMap map) { if (line.Coordinates.Length > 1) { var gp = new GraphicsPath(); int count = 0; var points = ClipValues(Transform.TransformToImage(line, map, SimplifyGeometryDuringRendering)); if (points.Length > 0) { gp.AddLines(points); g.DrawPath(pen, gp); } } }
public override void OnRenderAnimalionedView(System.Drawing.Graphics g, Model.DataModel data, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font FontText, System.Drawing.Font FontData) { }
/// <summary> /// Renders a MultiLineString to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="lines">MultiLineString to be rendered</param> /// <param name="pen">Pen style used for rendering</param> /// <param name="map">Map reference</param> public static void DrawMultiLineString(System.Drawing.Graphics g, IMultiLineString lines, System.Drawing.Pen pen, IMap map) { for (int i = 0; i < lines.Geometries.Length; i++) { DrawLineString(g, (ILineString)lines.Geometries[i], pen, map); } }
public override void OnRenderNormalView(System.Drawing.Graphics g, Model.DataModel dataModel, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font TextFont, System.Drawing.Font DataFont) { if (dataModel is CoordinateMultiDataModel) { CoordinateMultiDataModel datas = dataModel as CoordinateMultiDataModel; List <DataModel> dataList = datas.dataList; int i = 0; foreach (DataModel data in dataList) { data.Area.left = dataModel.Area.left + i * dataModel.Area.Width / 2; data.Area.right = data.Area.left + dataModel.Area.Width / 2 - MultiPadding; data.Area.bottom = dataModel.Area.bottom; data.Area.Width = data.Area.right - data.Area.left; data.Area.Height = (int)(data.mainData / MaxNum * EViewHeight); data.Area.top = dataModel.Area.top - data.Area.Height; i++; //绘制点 Rectangle item = new Rectangle(data.Area.left, data.Area.top, data.Area.Width, data.Area.Height); if (IsDrawDetailData) { //ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, CoordinateDataModelBean.Y_Data[i] + "", FontData, DataBrush, StartX, StartY, LeftPadding, padding); g.DrawString(data.mainData + "", DataFont, DataBrush, (item.X), item.Y - 2 * DataSize); } Brush bs = new SolidBrush(data.ModelColor); Brush bb = new SolidBrush(Color.FromArgb(100, data.ModelColor.R, data.ModelColor.G, data.ModelColor.B)); if (IsRadiusRectAngle) { GraphicsPath path = ReportViewUtils.CreateRoundedRectanglePath(item, data.Area.Width / 4); if (data.Area.IsMouseIn) { g.FillPath(bs, path); g.FillRectangle(bb, data.Area.left, CoordinateStartY - CoordinateHeight, data.Area.Width, CoordinateHeight); } else { g.FillPath(bs, path); } path.Dispose(); } else { if (data.Area.IsMouseIn) { g.FillRectangle(bs, item); g.FillRectangle(bb, dataModel.Area.left, CoordinateStartY - CoordinateHeight, dataModel.Area.Width, CoordinateHeight); } else { g.FillRectangle(bs, item); } } bb.Dispose(); bs.Dispose(); } } }
public void DisplayLine(int x1, int y1, int x2, int y2, System.Drawing.Pen col) { Graphics g = panel1.CreateGraphics(); // System.Drawing.Pen col = Pens.Black; g.DrawLine(col, x1, panel1.Height - y1, x2, panel1.Height - y2); }
/// <summary> /// c#生成缩略图 图片固定大小 缩略图加空白填充 /// </summary> /// <param name="fileName"></param> /// <param name="newFile"></param> /// <param name="desWidth"></param> /// <param name="desHeight"></param> public void SamllImageGengeratedFixedHW(string fileName, string newFile, int desWidth, int desHeight) { //容器高与宽 string backcolor = "#FFFFFF"; string borderColor = "#999999"; int penwidth = 0; int penhight = 0; System.Drawing.Image oimage = System.Drawing.Image.FromFile(fileName); //System.Drawing.Image oimage = System.Drawing.Image.FromStream(ostream); int owidth = oimage.Width; int oheight = oimage.Height; string hw = GetImageSize(owidth, oheight); string[] aryhw = hw.Split(';'); int twidth = Convert.ToInt32(aryhw[0]); int theight = Convert.ToInt32(aryhw[1]); //新建一个bmp图片 System.Drawing.Bitmap timage = new System.Drawing.Bitmap(desWidth, desHeight); //System.Drawing.Imaging.ImageFormat thisFormat = timage.RawFormat; //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(timage); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.Clear(System.Drawing.ColorTranslator.FromHtml(backcolor)); if (twidth < desWidth & theight == desHeight) { penwidth = desWidth - twidth; } else if (twidth == desWidth && theight < desHeight) { penhight = desHeight - theight; } else if (twidth < desWidth && theight < desHeight) { penwidth = desWidth - twidth; penhight = desHeight - theight; } int top = penhight / 2; int left = penwidth / 2; g.DrawImage(oimage, new System.Drawing.Rectangle(left, top, twidth, theight), new System.Drawing.Rectangle(0, 0, owidth, oheight), System.Drawing.GraphicsUnit.Pixel); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.ColorTranslator.FromHtml(borderColor)); g.DrawRectangle(pen, 0, 0, desWidth - 2, desHeight - 2); //string pathifile = Server.HtmlEncode(Request.PhysicalApplicationPath) + "image\\" +"t"+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".jpg"; try { //原图保存 // oimage.Save(pathifile,System.Drawing.Imaging.ImageFormat.Jpeg); //缩图图保存 timage.Save(newFile, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception ex) { throw ex; } finally { oimage.Dispose();//该方法如果不执行,后面删除图像等操作会提示文件被其他进程占用 2020-11-25 g.Dispose(); timage.Dispose(); } }
/// <summary> /// Renders a label to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="LabelPoint">Label placement</param> /// <param name="Offset">Offset of label in screen coordinates</param> /// <param name="font">Font used for rendering</param> /// <param name="forecolor">Font forecolor</param> /// <param name="backcolor">Background color</param> /// <param name="halo">Color of halo</param> /// <param name="rotation">Text rotation in degrees</param> /// <param name="text">Text to render</param> /// <param name="map">Map reference</param> public static void DrawLabel(System.Drawing.Graphics g, System.Drawing.PointF LabelPoint, System.Drawing.PointF Offset, System.Drawing.Font font, System.Drawing.Color forecolor, System.Drawing.Brush backcolor, System.Drawing.Pen halo, float rotation, string text, IMap map) { System.Drawing.SizeF fontSize = g.MeasureString(text, font); //Calculate the size of the text LabelPoint.X += Offset.X; LabelPoint.Y += Offset.Y; //add label offset if (rotation != 0 && rotation != float.NaN) { g.TranslateTransform(LabelPoint.X, LabelPoint.Y); g.RotateTransform(rotation); g.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2); if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent) { g.FillRectangle(backcolor, 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f); } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new System.Drawing.Point(0, 0), null); if (halo != null) { g.DrawPath(halo, path); } g.FillPath(new System.Drawing.SolidBrush(forecolor), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0); g.Transform = map.MapTransform; } else { if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent) { g.FillRectangle(backcolor, LabelPoint.X, LabelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f); } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(text, font.FontFamily, (int)font.Style, font.Size, LabelPoint, null); if (halo != null) { g.DrawPath(halo, path); } g.FillPath(new System.Drawing.SolidBrush(forecolor), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y); } }
/// <summary> /// Renders a multipolygon byt rendering each polygon in the collection by calling DrawPolygon. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="pols">MultiPolygon to render</param> /// <param name="brush">Brush used for filling (null or transparent for no filling)</param> /// <param name="pen">Outline pen style (null if no outline)</param> /// <param name="clip">Specifies whether polygon clipping should be applied</param> /// <param name="map">Map reference</param> public static void DrawMultiPolygon(System.Drawing.Graphics g, IMultiPolygon pols, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, IMap map) { for (int i = 0; i < pols.Geometries.Length; i++) { DrawPolygon(g, (IPolygon)pols.Geometries[i], brush, pen, clip, map); } }
private void switcher_tabPage_Paint(object sender, PaintEventArgs e) { //check if the program has been running too long if (DateTime.Now.DayOfYear == DOY + 5) { MessageBox.Show("You work too hard! go home, make a tea, and relax"); BackColor = Color.DarkBlue; } System.Drawing.Pen grid_Pen; grid_Pen = new System.Drawing.Pen(Color.Blue, 3); System.Drawing.Graphics switcher_Graphics = switcher_tabPage.CreateGraphics(); int h_Begin = out_comboBox1.Location.Y + (out_comboBox1.Height / 2); int h_End = out_comboBox12.Location.Y + (out_comboBox12.Height / 2); int h_Incr = out_comboBox2.Location.Y - out_comboBox1.Location.Y; int k = 0; for (int i = h_Begin; i <= h_End; i += h_Incr) { //draw the horizontal lines switcher_Graphics.DrawLine(grid_Pen, in_comboBox1.Location.X + (in_comboBox1.Width / 2), i, 1249, i); y_crosspoints[k++] = i; } int vh_Begin = in_comboBox1.Location.X + (in_comboBox1.Width / 2); int vh_End = in_comboBox11.Location.X + (in_comboBox11.Width / 2); int vh_Incr = in_comboBox3.Location.X - in_comboBox1.Location.X; //draw the higher vertical lines int j = 0; for (int i = vh_Begin; i <= vh_End; i += vh_Incr) { // switcher_Graphics.DrawLine(grid_Pen, i, in_comboBox1.Location.Y + in_comboBox1.Height, i, h_End); // x_crosspoints[j] = i; j += 2; } int vl_Begin = in_comboBox2.Location.X + (in_comboBox2.Width / 2); int vl_End = in_comboBox12.Location.X + (in_comboBox12.Width / 2); int vl_Incr = in_comboBox4.Location.X - in_comboBox2.Location.X; //draw the lower vertical lines j = 1; for (int i = vl_Begin; i <= vl_End; i += vl_Incr) { // switcher_Graphics.DrawLine(grid_Pen, i, in_comboBox2.Location.Y + in_comboBox2.Height, i, h_End); // x_crosspoints[j] = i; j += 2; } //draw upper bottom lines int vbl_Begin = in_comboBox13.Location.X + (in_comboBox13.Width / 2); int vbl_End = in_comboBox23.Location.X + (in_comboBox23.Width / 2); int vbl_Incr = in_comboBox15.Location.X - in_comboBox13.Location.X; j = 12; for (int i = vbl_Begin; i <= vbl_End; i += vbl_Incr) { // switcher_Graphics.DrawLine(grid_Pen, i, in_comboBox13.Location.Y, i, out_comboBox1.Location.Y + (out_comboBox1.Height / 2)); // x_crosspoints[j] = i; j += 2; } //draw lower bottom lines //draw upper bottom lines int vul_Begin = in_comboBox14.Location.X + (in_comboBox14.Width / 2); int vul_End = in_comboBox24.Location.X + (in_comboBox24.Width / 2); int vul_Incr = in_comboBox16.Location.X - in_comboBox14.Location.X; j = 13; for (int i = vul_Begin; i <= vul_End; i += vul_Incr) { // switcher_Graphics.DrawLine(grid_Pen, i, in_comboBox14.Location.Y, i, out_comboBox1.Location.Y + (out_comboBox1.Height / 2)); // x_crosspoints[j] = i; j += 2; } grid_Pen.Dispose(); switcher_Graphics.Dispose(); }
private void Button_Click(object sender, RoutedEventArgs e) { LoadFile(); UpdateResults(); double wpx = 1.00; double wpy = 1.00; var Height = MaxPointX; var Width = MaxPointY; if (MaxPointX > 10000 && MaxPointY > 10000) { Height = 10000; Width = 10000; wpx = Math.Round((10000.00 / MaxPointX), 2); wpy = Math.Round((10000.00 / MaxPointY), 2); if (wpx == 0) { wpx = 0.01; } if (wpy == 0) { wpy = 0.01; } } System.Drawing.Bitmap image = new Bitmap(Height, Width); Graphics graph = Graphics.FromImage(image); graph.Clear(System.Drawing.Color.Azure); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Black); for (int i = 0; i < solids.Count; i++) { graph.DrawBezier(pen, (float)(solids[i].X1 * wpx), (float)(solids[i].Y1 * wpy), (float)(solids[i].X2 * wpx), (float)(solids[i].Y2 * wpy), (float)(solids[i].X3 * wpx), (float)(solids[i].Y3 * wpy), (float)(solids[i].X4 * wpx), (float)(solids[i].Y4 * wpy)); } System.Drawing.Point[] pktPkt = new System.Drawing.Point[pkt.Count()]; for (int i = 0; i < pkt.Count; i++) { graph.DrawEllipse(pen, (float)pkt[i].X1, (float)pkt[i].Y1, 5, 5); } for (int i = 0; i < Punkty.Count; i++) { graph.DrawLine(pen, Convert.ToInt32(Punkty[i].X1 * wpx), Convert.ToInt32(Punkty[i].Y1 * wpy), Convert.ToInt32(Punkty[i].X2 * wpx), Convert.ToInt32(Punkty[i].Y2 * wpy)); } for (int i = 0; i < ellipse.Count; i++) { var width = 100 * ellipse[i].ratio; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Convert.ToInt32(ellipse[i].x * wpx), Convert.ToInt32(ellipse[i].y * wpy), Convert.ToInt32(width), 100); graph.DrawEllipse(pen, rect); } for (int i = 0; i < circles.Count; i++) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Convert.ToInt32(circles[i].X * wpx), Convert.ToInt32(circles[i].Y * wpy), Convert.ToInt32(circles[i].Radius * wpx), Convert.ToInt32(circles[i].Radius * wpx)); graph.DrawEllipse(pen, rect); } for (int i = 0; i < arcs.Count; i++) { int radius = 1; if (arcs[i].Z * wpx < 1) { radius = 1; } else { radius = Convert.ToInt32(arcs[i].Z * wpx); } System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Convert.ToInt32(arcs[i].X * wpx), Convert.ToInt32(arcs[i].Y * wpy), radius, radius); graph.DrawArc(pen, rect, arcs[i].startAngle, arcs[i].endAngle); } for (int i = 0; i < texts.Count; i++) { var item = ((float)(texts[i].textHeight * wpx)) > 10 ? 10 : (float)(texts[i].textHeight * wpx); graph.DrawString(texts[i].text, new Font(new System.Drawing.FontFamily("Arial"), item), System.Drawing.Brushes.Blue, texts[i].X * (float)wpx, texts[i].Y * (float)wpy); } for (int i = 0; i < mmtext.Count; i++) { var item = ((float)(texts[i].textHeight * wpx)) > 10 ? 10 : (float)(texts[i].textHeight * wpx); graph.DrawString(mmtext[i].text, new Font(new System.Drawing.FontFamily("Arial"), item), System.Drawing.Brushes.Blue, mmtext[i].X * (float)wpx, mmtext[i].Y * (float)wpy); } System.Drawing.Point[] pointsPolygon = new System.Drawing.Point[polygon.Count]; for (int i = 0; i < polygon.Count; i++) { pointsPolygon[i] = new System.Drawing.Point(Convert.ToInt32(polygon[i].X * wpx), Convert.ToInt32(polygon[i].Y * wpy)); var ts = pointsPolygon[i].X; var db = pointsPolygon[i].Y; } System.Drawing.Point[] pktlines = new System.Drawing.Point[lines.Count()]; for (int i = 0; i < lines.Count; i++) { pktlines[i] = new System.Drawing.Point(Convert.ToInt32(lines[i].X * wpx), Convert.ToInt32(lines[i].Y * wpy)); } System.Drawing.Point[] sppoints = new System.Drawing.Point[spline.Count()]; for (int i = 0; i < spline.Count; i++) { var x = 1.00; var y = 1.00; if (spline[i].X * wpx > 1) { x = spline[i].X * wpx; } if (spline[i].Y * wpy > 1) { y = spline[i].Y * wpy; } sppoints[i] = new System.Drawing.Point(Convert.ToInt32(x), Convert.ToInt32(y)); } System.Drawing.Point[] hatchPoints = new System.Drawing.Point[hatchList.Count()]; for (int i = 0; i < hatchList.Count; i++) { var x = 1.00; var y = 1.00; hatchPoints[i] = new System.Drawing.Point(Convert.ToInt32(hatchList[i].X * wpx), Convert.ToInt32(hatchList[i].Y * wpy)); } if (hatchPoints.Count() > 0) { graph.DrawPolygon(pen, hatchPoints); } if (pktlines.Count() > 0) { graph.DrawPolygon(pen, pktlines); } if (pointsPolygon.Count() > 0) { graph.DrawPolygon(pen, pointsPolygon); } if (sppoints.Count() > 0) { graph.DrawCurve(pen, sppoints); } System.Drawing.Point[] attpoints = new System.Drawing.Point[att.Count()]; for (int i = 0; i < att.Count; i++) { var x = 1.00; var y = 1.00; if (att[i].X * wpx > 1) { x = att[i].X * wpx; } if (att[i].Y * wpy > 1) { y = att[i].Y * wpy; } attpoints[i] = new System.Drawing.Point(Convert.ToInt32(x), Convert.ToInt32(y)); } //graph.DrawLines(pen, attpoints); image.Save("trala.jpeg", System.Drawing.Imaging.ImageFormat.Png); var ScreenCapture = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( image.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(10000, 10000)); abc.Source = ScreenCapture; }
/// <summary> /// Renders a polygon to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="pol">Polygon to render</param> /// <param name="brush">Brush used for filling (null or transparent for no filling)</param> /// <param name="pen">Outline pen style (null if no outline)</param> /// <param name="clip">Specifies whether polygon clipping should be applied</param> /// <param name="map">Map reference</param> public static void DrawPolygon(System.Drawing.Graphics g, IPolygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, IMap map) { try { if (pol.Shell == null) { return; } if (pol.Shell.Coordinates.Length > 2) { var points = Transform.TransformToImage(pol.Shell, map, SimplifyGeometryDuringRendering); var solidBrush = brush as SolidBrush; if (solidBrush != null && solidBrush.Color.A != 0) { g.FillPolygon(brush, points, FillMode.Alternate); } if (pen != null) { g.DrawPolygon(pen, points); } for (int i = 0; i < pol.Holes.Length; i++) { points = Transform.TransformToImage(pol.Holes[i], map, SimplifyGeometryDuringRendering); if (solidBrush != null && solidBrush.Color.A != 0) { g.FillPolygon(brush, points); } if (pen != null) { g.DrawPolygon(pen, points); } } } } catch (InvalidOperationException e) { log.WarnFormat("Error during rendering", e); } catch (OverflowException e) { log.WarnFormat("Error during rendering", e); } }
public static void DrawGradient(Graphics _graphics, string channel) { switch (channel) { case "Red": for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(i, 0, 0)); _graphics.DrawLine(p, i, 0, i, 20); } break; case "Green": for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(0, i, 0)); _graphics.DrawLine(p, i, 0, i, 20); } break; case "Blue": for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(0, 0, i)); _graphics.DrawLine(p, i, 0, i, 20); } break; case "Cyan": for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(i, 255, 255)); _graphics.DrawLine(p, i, 0, i, 20); } break; case "Magenta": for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, i, 255)); _graphics.DrawLine(p, i, 0, i, 20); } break; case "Yellow": for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, 255, i)); _graphics.DrawLine(p, i, 0, i, 20); } break; default: for (int i = 0; i <= 255; i++) { System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.FromArgb(i, i, i)); _graphics.DrawLine(p, i, 0, i, 20); } break; } }
public BarRenderer(int minimum, int maximum, System.Drawing.Pen pen, Color start, Color end) : this(minimum, maximum) { this.Pen = pen; this.SetGradient(start, end); }
public BarRenderer(int minimum, int maximum, System.Drawing.Pen pen, System.Drawing.Brush brush) : this(minimum, maximum) { this.Pen = pen; this.Brush = brush; this.UseStandardBar = false; }
private void MainGraphicPanel_Paint(object sender, PaintEventArgs e) { string args = "str"; { string returnvalue; returnvalue = args + " = Console.ReadLine()"; Console.WriteLine(returnvalue); //return returnvalue } args = "mystring , 100 , FILE"; { string result = ""; var x = args.Split(','); var s = x.Select(n => n.Trim()); result = "" + s.ElementAt(2) + ".Read(" + s.ElementAt(0) + ".ToCharArray(), 0, " + s.ElementAt(1) + ")"; Console.WriteLine(result); } //fopen("filename", "r"); args = "\"filename\", \"r\""; { string result = ""; var x = args.Split(','); var s = x.Select(n => n.Trim()); result = "new FileStream(" + s.ElementAt(0) + ", FileMode.Open)"; Console.WriteLine(result); } args = "File"; { string result = ""; result = "" + args + ".Close()"; } args = "string"; { string result; result = "Int32.Parse(" + args + ")"; Console.WriteLine(result); } Int32 f = 45; var a = f.GetType(); args = "string"; { string result; result = args + ".Length()"; Console.WriteLine(result); } System.Drawing.Graphics g = e.Graphics; if (player != null) { Image image = player.GetImage(currentFrame); if (image != null) { g.DrawImage(image, curX + player.sprites[currentFrame].pos.X + drawOffSet.X + (MainGraphicPanel.Width / 2) - image.Width / 2 * scaleX, curY + player.sprites[currentFrame].pos.Y + drawOffSet.Y + (MainGraphicPanel.Height / 2) - image.Height / 2 * scaleY, image.Width * scaleX, image.Height * scaleY); } if (ToggleHitbox.Checked) { foreach (var i in player.sprites[currentFrame].hitBoxes) { i.Draw(g, new Point(MainGraphicPanel.Width + (int)drawOffSet.X, MainGraphicPanel.Height + (int)drawOffSet.Y)); } } } if (displayGrid) { var myPen = new System.Drawing.Pen(System.Drawing.Color.Green); myPen.Width = 1; g.DrawLine(myPen, (int)(MainGraphicPanel.Width / 2), 0, MainGraphicPanel.Width / 2, MainGraphicPanel.Height); g.DrawLine(myPen, 0, (int)(MainGraphicPanel.Height / 2), MainGraphicPanel.Width, (int)(MainGraphicPanel.Height / 2)); myPen = new System.Drawing.Pen(System.Drawing.Color.Blue); g.DrawLine(myPen, 0, (int)(MainGraphicPanel.Height / 2) + 50, MainGraphicPanel.Width, (int)(MainGraphicPanel.Height / 2) + 50); myPen.Dispose(); } if (hitBox != null) { hitBox.Draw(g, new Point(MainGraphicPanel.Width, MainGraphicPanel.Height)); } if (filmRoll != null) { filmRoll.panel2.Invalidate(); } }
public System.Windows.Media.Imaging.BitmapImage BuildImage(bool Components, bool SentencesLine, bool SentencesLines, bool SentencesBox) { //Here create the Bitmap to the know height, width and format System.Drawing.Rectangle cloneRect = new System.Drawing.Rectangle(0, 0, m_Image.Width, m_Image.Height); System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format24bppRgb; Bitmap cloneBitmap = resultBitmap.Clone(cloneRect, format); Graphics Graphics = Graphics.FromImage(cloneBitmap); System.Drawing.Pen PenBlue = new System.Drawing.Pen(System.Drawing.Color.Blue); System.Drawing.Pen PenRed = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen PenGray = new System.Drawing.Pen(System.Drawing.Color.Gray); if (Components) { foreach (PageComponent Component in PageImage.Components) { if (Component.Type == ePageComponentType.eCharacter) { Graphics.DrawRectangle(PenBlue, Component.Area); } } } System.Drawing.Point PointFrom, PointTo; foreach (Sentence Sentence in PageImage.Sentences) { if (SentencesBox) { Graphics.DrawRectangle(PenRed, Sentence.Area); } if (SentencesLines) { int Delta; Delta = (int)(Math.Sin(Sentence.Slope) * Sentence.Area.Width / 2); PointFrom = new System.Drawing.Point(Sentence.Area.Left, Sentence.PositionCenter.Y - (int)((Sentence.PositionCenter.X - Sentence.Area.Left) * Math.Sin(Sentence.Slope))); PointTo = new System.Drawing.Point(Sentence.Area.Right, Sentence.PositionCenter.Y + (int)((Sentence.PositionCenter.X - Sentence.Area.Left) * Math.Sin(Sentence.Slope))); Graphics.DrawLine(PenRed, PointFrom, PointTo); PointFrom = new System.Drawing.Point(Sentence.Area.Left, Sentence.PositionBase.Y - (int)((Sentence.PositionBase.X - Sentence.Area.Left) * Math.Sin(Sentence.Slope))); PointTo = new System.Drawing.Point(Sentence.Area.Right, Sentence.PositionBase.Y + (int)((Sentence.PositionBase.X - Sentence.Area.Left) * Math.Sin(Sentence.Slope))); Graphics.DrawLine(PenRed, PointFrom, PointTo); PointFrom = new System.Drawing.Point(Sentence.Area.Left, Sentence.PositionDescent.Y - (int)((Sentence.PositionDescent.X - Sentence.Area.Left) * Math.Sin(Sentence.Slope))); PointTo = new System.Drawing.Point(Sentence.Area.Right, Sentence.PositionDescent.Y + (int)((Sentence.PositionDescent.X - Sentence.Area.Left) * Math.Sin(Sentence.Slope))); Graphics.DrawLine(PenRed, PointFrom, PointTo); } PointFrom = PointTo = new System.Drawing.Point(0, 0); foreach (PageComponent Component in Sentence.Components) { if (Component.Type == ePageComponentType.eCharacter) { PointFrom = PointTo; PointTo = Component.CenterPoint; if (!(PointFrom.X == 0 && PointFrom.Y == 0) && PointFrom != PointTo && SentencesLine) { Graphics.DrawLine(PenGray, PointFrom, PointTo); } } if (Component.Type == ePageComponentType.eSpace && SentencesLine) { Graphics.DrawRectangle(PenGray, Component.Area); } } //PointTo = Sentence.BaseLine[0]; //foreach (Point Point in Sentence.BaseLine) //{ // PointFrom = PointTo; // PointTo = Point; // Graphics.DrawLine(PenGray, PointFrom, PointTo); //} //PointTo = Sentence.DescentLine[0]; //foreach (Point Point in Sentence.DescentLine) //{ // PointFrom = PointTo; // PointTo = Point; // Graphics.DrawLine(PenGray, PointFrom, PointTo); //} } System.IO.MemoryStream ms = new System.IO.MemoryStream(); cloneBitmap.Save(ms, ImageFormat.Bmp); System.Windows.Media.Imaging.BitmapImage returnImage = new System.Windows.Media.Imaging.BitmapImage(); returnImage.BeginInit(); returnImage.StreamSource = new System.IO.MemoryStream(ms.ToArray()); returnImage.EndInit(); return(returnImage); }
public override void childPaint(System.Drawing.Graphics g, Model.DataModel Data, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font font_Text, System.Drawing.Font font_Data) { if (isFirst) { oldColor = linePen.Color; isFirst = false; } if (Data != null) { ///建议把绘制的直接写在这里 if (Data.Area.IsMouseIn) { linePen.Color = ReportViewUtils.perferRed; } else { linePen.Color = oldColor; } ChildDataModel data = (ChildDataModel)Data; utils.drawReportView(g, RePortViewStyle.Arc_rectangle, Data.Area.left, Data.Area.top, Data.Area.right - Data.Area.left, Data.Area.bottom - Data.Area.top, linePen.Color, Data.mainText, Data.mainData, 200, data.childText, data.childData, 10, 16); int startX = Data.Area.left; //圆点的大小 //int CircleRaius = 10; //SolidBrush sbrush1 = new SolidBrush(Color.FromArgb(150, 1, 77, 103)); //Rectangle rect = new Rectangle(startX, startY, width, height); //float realAngle = 360 * Data_InArc * 1.0f / Data_InArc_Max; ////顺时针绘制 //float startAngle = 360 - realAngle; //g.DrawArc(myPen, rect, startAngle, realAngle); ////绘制圆弧内的字体 //g.DrawString(Text_InArc, font_Text, myBrush, (width - TextSize * (Text_InArc.Length + 2)) / 2 + startX, height / 2 - 2 * padding + startY); ////绘制圆弧内的数据 //g.DrawString(Data_InArc + "", font_Data, DataBrush, (width - DataSize * (Data_InArc.ToString().Length)) / 2 + startX, height / 2 + padding + startY); ////绘制圆弧外的字体 //Rectangle Arc_Out = new Rectangle(startX, startY + height + 4 * padding / 3, width, 30); //g.FillEllipse(sbrush1, Arc_Out); //g.DrawString(Text_OutArc + Data_OutArc + "%", font_Text, TextBrush, (width - TextSize * (Text_InArc.Length + Data_OutArc.ToString().Length + 3)) / 2 + startX, height + 2 * padding + startY); ////定位圆点 //int y = (int)(Math.Sin(startAngle / 180 * Math.PI) * width / 2); //int x = (int)(Math.Cos(startAngle / 180 * Math.PI) * width / 2); //Rectangle rect_Circle = new Rectangle(startX + width / 2 - CircleRaius / 2 + x, startY + height / 2 - CircleRaius / 2 + y, CircleRaius, CircleRaius); ////绘制圆点 //g.FillEllipse(myBrush, rect_Circle); //sbrush1.Dispose(); } }
public BahtinovImage GrabBahtinov() { var bahtinovImage = new BahtinovImage(); Bitmap convertedSource; if (originalSource.Format != System.Windows.Media.PixelFormats.Gray8) { if (originalSource.Format != System.Windows.Media.PixelFormats.Gray16) { using (var imgToConvert = ImageUtility.BitmapFromSource(originalSource, System.Drawing.Imaging.PixelFormat.Format48bppRgb)) { convertedSource = new Grayscale(0.2125, 0.7154, 0.0721).Apply(imgToConvert); } convertedSource = ImageUtility.Convert16BppTo8Bpp(ImageUtility.ConvertBitmap(convertedSource, System.Windows.Media.PixelFormats.Gray16)); } else { convertedSource = ImageUtility.Convert16BppTo8Bpp(originalSource); } } else { convertedSource = ImageUtility.BitmapFromSource(originalSource, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); convertedSource.Palette = ImageUtility.GetGrayScalePalette(); } using (var focusEllipsePen = new System.Drawing.Pen(System.Drawing.Brushes.Green, 1)) { using (var intersectEllipsePen = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1)) { var mediaColor = backgroundColor; var drawingColor = System.Drawing.Color.FromArgb(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B); using (var linePen = new System.Drawing.Pen(drawingColor, 1)) { using (var bahtinovedBitmap = new Bitmap(convertedSource.Width, convertedSource.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) { Graphics graphics = Graphics.FromImage(bahtinovedBitmap); graphics.DrawImage(convertedSource, 0, 0); /* Apply filters and detection*/ CannyEdgeDetector filter = new CannyEdgeDetector(); filter.GaussianSize = 10; filter.ApplyInPlace(convertedSource); HoughLineTransformation lineTransform = new HoughLineTransformation(); lineTransform.ProcessImage(convertedSource); HoughLine[] lines = lineTransform.GetMostIntensiveLines(6); List <Line> bahtinovLines = new List <Line>(); foreach (HoughLine line in lines) { var k = TranslateHughLineToLine(line, bahtinovedBitmap.Width, bahtinovedBitmap.Height); bahtinovLines.Add(k); } float x1, x2, y1, y2; if (bahtinovLines.Count == 6) { var orderedPoints = bahtinovLines.OrderBy(x => 1.0d / x.Slope).ToList(); var threeLines = new List <Line>(); for (var i = 0; i < orderedPoints.Count(); i += 2) { var l1 = orderedPoints[i]; var l2 = orderedPoints[i + 1]; var inter = (l1.Intercept + l2.Intercept) / 2.0f; var slope = (l1.Slope + l2.Slope) / 2.0f; var centerLine = Line.FromSlopeIntercept(slope, inter); threeLines.Add(centerLine); x1 = 0; x2 = convertedSource.Width; y1 = double.IsInfinity(centerLine.Slope) ? centerLine.Intercept : centerLine.Slope + centerLine.Intercept; y2 = double.IsInfinity(centerLine.Slope) ? centerLine.Intercept : (centerLine.Slope * (convertedSource.Width) + centerLine.Intercept); graphics.DrawLine( linePen, new PointF(x1, y1), new PointF(x2, y2)); } /* Intersect outer bahtinov lines */ var intersection = threeLines[0].GetIntersectionWith(threeLines[2]); if (intersection.HasValue) { /* get orthogonale to center line through intersection */ var centerBahtinovLine = threeLines[1]; var orthogonalSlope = -1.0f / centerBahtinovLine.Slope; var orthogonalIntercept = intersection.Value.Y - orthogonalSlope * intersection.Value.X; var orthogonalCenter = Line.FromSlopeIntercept(orthogonalSlope, orthogonalIntercept); var intersection2 = centerBahtinovLine.GetIntersectionWith(orthogonalCenter); if (intersection2.HasValue && !double.IsInfinity(intersection2.Value.X)) { x1 = intersection.Value.X; y1 = intersection.Value.Y; x2 = intersection2.Value.X; y2 = intersection2.Value.Y; bahtinovImage.Distance = intersection.Value.DistanceTo(intersection2.Value); var t = bahtinovImage.Distance * 4 / bahtinovImage.Distance; var x3 = (float)((1 - t) * x1 + t * x2); var y3 = (float)((1 - t) * y1 + t * y2); var r = 10; graphics.DrawEllipse( intersectEllipsePen, new RectangleF(x3 - r, y3 - r, 2 * r, 2 * r)); graphics.DrawEllipse( focusEllipsePen, new RectangleF(x2 - r, y2 - r, 2 * r, 2 * r)); graphics.DrawLine( intersectEllipsePen, new PointF(x3, y3), new PointF(x2, y2)); } } } var img = ImageUtility.ConvertBitmap(bahtinovedBitmap, System.Windows.Media.PixelFormats.Bgr24); convertedSource.Dispose(); img.Freeze(); bahtinovImage.Image = img; return(bahtinovImage); } } } } }
public BarRenderer(System.Drawing.Pen pen, System.Drawing.Brush brush) : this() { this.Pen = pen; this.Brush = brush; this.UseStandardBar = false; }
public override void Draw(System.Drawing.Graphics g, System.Drawing.Pen p) { p.Color = Color.Gray; g.DrawRectangle(p, drawable); }