public void Highlight(Figure highlightObject, PictureBox pictureBox) { Graphics g = pictureBox.CreateGraphics(); highlightObject.Pen = SystemPens.Highlight; highlightObject.Draw(g, highlightObject.Pen, highlightObject.StartPoint, highlightObject.FinishPoint); }
// Función que permite graficar un triángulo en base a los valores de los tres // vértices representados por tres puntos en un plano. public void GraphShape(PictureBox picCanvas) { mGraph = picCanvas.CreateGraphics(); picCanvas.Refresh(); mPen = new Pen(Color.Teal, 3); mAngle = 54.0f; mAngle = ConvertGradesToRadians(mAngle); mB = mL * (float)Math.Sin(mAngle); mAngle = 36.0f; mAngle = ConvertGradesToRadians(mAngle); mA = mL * (float)Math.Sin(mAngle); mAngle = 72.0f; mAngle = ConvertGradesToRadians(mAngle); mD = mL * (float)Math.Sin(mAngle); mAngle = 18.0f; mAngle = ConvertGradesToRadians(mAngle); mC = mL * (float)Math.Sin(mAngle); mP1.X = mB; mP1.Y = 0; mP2.X = 2 * mB; mP2.Y = mA; mP3.X = mC + mL; mP3.Y = mA + mD; mP4.X = mC; mP4.Y = mA + mD; mP5.X = 0; mP5.Y = mA; mGraph.DrawLine(mPen, mP1.X * SF, mP1.Y * SF, mP2.X * SF, mP2.Y * SF); mGraph.DrawLine(mPen, mP2.X * SF, mP2.Y * SF, mP3.X * SF, mP3.Y * SF); mGraph.DrawLine(mPen, mP3.X * SF, mP3.Y * SF, mP4.X * SF, mP4.Y * SF); mGraph.DrawLine(mPen, mP4.X * SF, mP4.Y * SF, mP5.X * SF, mP5.Y * SF); mGraph.DrawLine(mPen, mP5.X * SF, mP5.Y * SF, mP1.X * SF, mP1.Y * SF); }
internal void stripTo(PictureBox to) { using (Graphics windowGraphics = to.CreateGraphics()) { Size size = to.ClientSize; int count = 0; int colorIndex = 0; Color color; using (Bitmap outmap = new Bitmap(size.Width, size.Height)) { foreach (int x in Enumerable.Range(0, size.Width - 1)) { if (count % 21 == 20) { color = Color.Black; colorIndex++; } else { color = _strip[colorIndex]; } foreach (int y in Enumerable.Range(0, size.Height - 1)) { outmap.SetPixel(x, y, color); } count++; } windowGraphics.DrawImage(outmap, new Rectangle(new Point(0, 0), size)); } } }
public BoardGrafix(PictureBox boardArea) { game = new Sodoku(); Board = boardArea; g = Board.CreateGraphics(); BoardSize = boardArea.Width; if (boardArea.Height < BoardSize) { BoardSize = boardArea.Height; topLeft = new Point((boardArea.Width - BoardSize) / 2, 0); bottomRight = new Point(topLeft.X + BoardSize - 1, BoardSize - 1); } else { topLeft = new Point(0, (boardArea.Height - BoardSize) / 2); bottomRight = new Point(BoardSize - 1, topLeft.Y + BoardSize - 1); } // calc atom size cellAtomSize = (BoardSize - 30) / 27; frameSize = 27 * cellAtomSize + 30; int gridOffset = (BoardSize - frameSize) / 2; gridAnchor = new Point(topLeft.X + gridOffset, topLeft.Y + gridOffset); cellSize = 3 * cellAtomSize + 2; // exl grid frame SodokuBoard = new Board(gridAnchor, g, cellAtomSize); //SodokuBoard.SetRank(new GridLocation(6, 5), 9); SodokuBoard.ShowPossibleMoves = false; HasSelection = false; LoadAvailableMoves(); MoveHistory = new List <GridLocation>(); }
private void PlayCard(PictureBox sender, int value) { if (!GameRunning()) { return; } if (sender.Text == "Blank") { MessageBox.Show("This is an empty card."); } else { if (_mainPlayer.Health > 0) { Card c = _mainPlayer.Cardset.Find(x => x.Value == value); sender.Text = "Blank"; sender.CreateGraphics().Clear(Color.Wheat); _mainPlayer.ChooseCard(c); } foreach (Player p in _players) { if (p is CharacterAI) { CharacterAI cai = (CharacterAI)p; cai.PlayCard(); } } // check cards checkPosition(); } }
public override void Draw(PictureBox pictureBox) { Graphics g = pictureBox.CreateGraphics(); g.Clear(Color.White); g.DrawEllipse(new Pen(Color.Black), CenterPoint.X, CenterPoint.Y, RadiusX, RadiusY); }
public MainThread(PictureBox picturebox) { btm = new Bitmap(picturebox.Width, picturebox.Height); g = Graphics.FromImage(btm); fg = picturebox.CreateGraphics(); mapManager = new MapManager(); }
public Test(){ _pictureBox = new PictureBox(); _image = new Bitmap("WCC_2.jpg"); _pictureBox.Size = _image.Size; _graphics = _pictureBox.CreateGraphics(); _bottomLeft = new Point(_pictureBox.Left, _pictureBox.Bottom); _bottomRight = new Point(_pictureBox.Right, _pictureBox.Bottom); _panel = new FlowLayoutPanel(); _panel.Dock = DockStyle.Top; _panel.Height = _image.Height; _textbox = new TextBox(); _fillButton = new Button(); _fillButton.Text = "Fill Tank"; _fillButton.MouseMove += new MouseEventHandler(FillTank); _drainButton = new Button(); _drainButton.Text = "Drain Tank"; _drainButton.MouseMove += new MouseEventHandler(DrainTank); _panel.Controls.Add(_pictureBox); _panel.Controls.Add(_fillButton); _panel.Controls.Add(_drainButton); this.Controls.Add(_panel); }
/// <summary> /// Initializes the non-serialized fields of the crossing. /// </summary> public void InitializeCrossing() { tlTimer = new Timer(); tlTimer.Interval = 1000; tlTimer.Tick += tlTimer_tick; gr = pb_trans.CreateGraphics(); }
public Crossing(Point location, PictureBox pb_background, PictureBox pb_transparrent) { this.location = location; this.pb_back = pb_background; this.pb_trans = pb_transparrent; this.neighbours = new Crossing[4]; random = new Random(); percentages = new int[4, 3] { { 30, 30, 40 }, { 30, 30, 40 }, { 30, 30, 40 }, { 30, 30, 40 } }; carFrequency = new int[4] { 5000, 5000, 5000, 5000 }; incomingStreams = new string[4] { "north", "east", "south", "west" }; laneInList = new List <LaneIn>(); laneOutList = new List <LaneOut>(); groups = new TrafficLightGroups(); gr = pb_trans.CreateGraphics(); spawns = new List <Point>(); tlTimer = new Timer(); tlTimer.Interval = 1000; tlTimer.Tick += tlTimer_tick; }
public CatchMeIfYouCan() { InitializeComponent(); MainFrame = pictureBox1; Frame = new Bitmap(MainFrame.Width, MainFrame.Height); PictureBoxGraph = MainFrame.CreateGraphics(); }
public void DibujaEslabon(PictureBox picturebox, Graphics papel) { this.myPicturebox = picturebox; this.papel = papel; myPicturebox.CreateGraphics(); papel.DrawLine(new Pen(Color.Black, 3), this.pt1, this.pt2); }
private void Form6_Paint(object sender, PaintEventArgs e) { mypb.Width = 300; mypb.Height = 300; Graphics g = mypb.CreateGraphics(); Brush mybr = new SolidBrush(Color.Honeydew); float[] angles = { 0, 130, 205, 290, 360 }; Color[] colors = { Color.LightGoldenrodYellow, Color.PaleTurquoise, Color.RoyalBlue, Color.Purple }; g.Clear(Color.Ivory); Rectangle r = new Rectangle(10, 50, 250, 150); for (int i = 1; i < angles.Length; ++i) { mybr = new SolidBrush(colors[i - 1]); g.FillPie(mybr, r, angles[i - 1], angles[i] - angles[i - 1]); } g.DrawEllipse(Pens.Black, r); }
private void UpdateImage() { if (bmp.Handle != IntPtr.Zero) //以下代码将原始图像数据用来进行图像! { Win32Api.CopyMemory((IntPtr)bmp.Pointer, (IntPtr)DataCopy, bmp.Stride * bmp.Height); } switch (method) { case "Bin": AdjustEffect.Bin(bmp, (int)trbValue.Value); break; case "Gama": AdjustEffect.Gama(bmp, (int)trbValue.Value); break; case "FilmStyle": AdjustEffect.FilmStyle(bmp, (int)trbValue.Value); break; } Graphics G = canvas.CreateGraphics(); IntPtr Hdc = G.GetHdc(); bmp.DrawImage(Hdc, 0, 0, canvas.Width, canvas.Height, 0, 0, bmp.Width, bmp.Height); G.ReleaseHdc(); G.Dispose(); canvas.Invalidate(); }
private void pbxMain_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left || e.Button == System.Windows.Forms.MouseButtons.Right) { //memorize last point clicked Point vPrevPoint = mLastPoint; mLastPoint = new Point(e.X, e.Y); //make a line? if (vPrevPoint != Point.Empty) { PictureBox vPbx = (PictureBox)sender; Brush vBrush = (e.Button == System.Windows.Forms.MouseButtons.Left ? BrushLeft : BrushRight); using (Graphics vG = vPbx.CreateGraphics()) { Pen vP = new Pen(vBrush, 10f); vP.StartCap = LineCap.Round; vP.EndCap = LineCap.Round; vP.DashStyle = DashStyle.Solid; vP.LineJoin = LineJoin.Round; vG.DrawLine(vP, vPrevPoint, mLastPoint); } } //draws some balls ... nice but lines should be better //using (Graphics vG = vPbx.CreateGraphics()) { // vG.FillEllipse(vBrush, e.X, e.Y, 10, 10); //} } }
public void GraficadoraRellenoY(PictureBox cuadradoY, ComboBox color) { mGraficosY = cuadradoY.CreateGraphics(); int rango = (int)mLado * 10; PointF[] PuntosL; PointF[] PuntosR; PuntosL = LinePoints.ObtenerPuntos(mA, mC, rango); PuntosR = LinePoints.ObtenerPuntos(mB, mD, rango); PointF[] PuntosEntreLineas; for (int i = 0; i < rango; i++) { PuntosEntreLineas = LinePoints.ObtenerPuntos(PuntosL[i], PuntosR[i], rango); for (int j = 0; j < rango; j++) { Point pixel = new Point(); pixel.X = (int)PuntosEntreLineas[j].X; pixel.Y = (int)PuntosEntreLineas[j].Y; Rectangle rect = new Rectangle(pixel, new Size(2, 2)); Thread.Sleep(20); mGraficosY.DrawRectangle(mPen, rect); } } }
public void Add(PictureBox pbScreen, Image initialImage, Action <object, PaintEventArgs> p, int zoom) { this.zoom = zoom; this.pbScreen = pbScreen; System.Drawing.BufferedGraphicsContext currentContext; currentContext = BufferedGraphicsManager.Current; imageSize = new Size(initialImage.Size.Width, initialImage.Size.Height); pbScreen.Size = new Size(imageSize.Width * zoom, imageSize.Height * zoom); bgPlane = currentContext.Allocate(pbScreen.CreateGraphics(), pbScreen.DisplayRectangle); if (p != null) { pbScreen.Paint += new System.Windows.Forms.PaintEventHandler(p); } bmpPlane = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format32bppArgb); bmpPlaneW = imageSize.Width; bmpPlaneH = imageSize.Height; BitmapData bdPlane = bmpPlane.LockBits(new Rectangle(0, 0, bmpPlane.Width, bmpPlane.Height), ImageLockMode.ReadOnly, bmpPlane.PixelFormat); baPlaneBuffer = new byte[bdPlane.Stride * bmpPlane.Height]; System.Runtime.InteropServices.Marshal.Copy(bdPlane.Scan0, baPlaneBuffer, 0, baPlaneBuffer.Length); bmpPlane.UnlockBits(bdPlane); bgPlane.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; bgPlane.Graphics.DrawImage(initialImage, 0, 0, imageSize.Width * zoom, imageSize.Height * zoom); }
/// <summary> /// This functions draw the OrGate in the picturebox pic in the coordinates of the object /// </summary> /// <param name="pic">the picturebox in which the gate is going to be drawn</param> public override void drawGate(ref PictureBox pic) { Graphics g = pic.CreateGraphics(); Point Coord = new Point((col - 1) * 50 + 1, (row - 1) * 50 + 1); g.DrawImageUnscaled(Image.FromFile("../../../../../OrGate.jpg"), Coord); }
private void Form13_Paint(object sender, PaintEventArgs e) { pb.Width = 500; pb.Height = 300; Graphics g = pb.CreateGraphics(); Point[] myPoints = { new Point(0, 0), new Point(200, 0), new Point(200, 200), new Point(0, 200) }; PathGradientBrush myBrush = new PathGradientBrush( myPoints); Color[] colors = { Color.FromArgb(255, 0, 128, 0), Color.FromArgb(255, 128, 0, 255), Color.FromArgb(255, 0, 128, 128) }; float[] relativePositions = { 0.0F, 0.4F, 1.0F }; ColorBlend colorBlend = new ColorBlend(); colorBlend.Colors = colors; colorBlend.Positions = relativePositions; myBrush.InterpolationColors = colorBlend; g.FillRectangle(myBrush, 0, 0, 200, 200); }
public override void Draw(PictureBox pictureBox) { Graphics g = pictureBox.CreateGraphics(); g.Clear(Color.White); if (Point1 != null && Point2 == null && Point3 == null && Point4 == null) { g.FillRectangle(Brushes.Black, Point1.X, Point1.Y, 3, 3); } if (Point1 != null && Point2 != null) { g.DrawLine(Pens.Black, Point1.X, Point1.Y, Point2.X, Point2.Y); } if (Point2 != null && Point3 != null) { g.DrawLine(Pens.Black, Point2.X, Point2.Y, Point3.X, Point3.Y); } if (Point3 != null && Point4 != null) { g.DrawLine(Pens.Black, Point3.X, Point3.Y, Point4.X, Point4.Y); } if (Point1 != null && Point4 != null) { g.DrawLine(Pens.Black, Point4.X, Point4.Y, Point1.X, Point1.Y); } }
public Color Click(int x, int y) { this.x = x; this.y = y; Graphics g = picture.CreateGraphics(); Paint(null, new PaintEventArgs(g, new Rectangle())); g.Dispose(); int row = 0, col = 0; foreach (Color color in colors) { if (boxSide * row <= x && x < boxSide * row + boxSide && boxSide * col <= y && y < boxSide * col + boxSide) { return(color); } row += 1; if (row >= rowCount) { row = 0; col += 1; } } return(Color.Black); }
internal void straightCopy(PictureBox to) { using (Graphics windowGraphics = to.CreateGraphics()) { windowGraphics.DrawImage(_bitmap, new Rectangle(new Point(0, 0), to.Size)); } }
//ptlist长度必须等于xmax值,ymax要与ptlist中最大值一致 public void DrawLineS(Color color, int Xmax, int Ymax, ref PictureBox picbox, ref short[] ptlist) { mybitmap = new Bitmap(picbox.Width, picbox.Height); //设定位图大小 Graphics doublebufferg = Graphics.FromImage(mybitmap); //从位图上获取“画布” Rectangle rect = new Rectangle(0, 0, picbox.Width, picbox.Height); doublebufferg.FillRectangle(new SolidBrush(Color.Black), rect); //画X和Y轴 DrawXY(ref doublebufferg, picbox); //Y轴上的刻度 SetYAxis(ref doublebufferg, picbox, Ymax); //X轴上的刻度 //SetXAxis(ref doublebufferg, picbox, Xmax); xkedu = (float)Xmax / (picbox.Width); for (int i = 0; i < pdata.Length; i++) { pdata[i].Y = (ptlist[i * (int)xkedu] + 32768) / ykedu; pdata[i].X = i; //doublebufferg.FillEllipse(new SolidBrush(Color.White), pdata[i].X, pdata[i].Y,2,2); } doublebufferg.DrawLines(new Pen(color), pdata); //将缓冲中的位图绘制到我们的窗体上 using (Graphics g1 = picbox.CreateGraphics())//创建 PictureBox窗体的画布 { g1.DrawImage(mybitmap, 0, 0); doublebufferg.Dispose(); } }
private void RotateFormCenter(PictureBox pb, float angle) { Graphics graphics = pb.CreateGraphics(); graphics.Clear(pb.BackColor); //装入图片 Bitmap image = new Bitmap(imageList1.Images[0]); //获取当前窗口的中心点 Rectangle rect = new Rectangle(0, 0, pb.Width, pb.Height); PointF center = new PointF(rect.Width / 2, rect.Height / 2); float offsetX = 0; float offsetY = 0; offsetX = center.X - image.Width / 2; offsetY = center.Y - image.Height / 2; //构造图片显示区域:让图片的中心点与窗口的中心点一致 RectangleF picRect = new RectangleF(offsetX, offsetY, image.Width, image.Height); PointF Pcenter = new PointF(picRect.X + picRect.Width / 2, picRect.Y + picRect.Height / 2); // 绘图平面以图片的中心点旋转 graphics.TranslateTransform(Pcenter.X, Pcenter.Y); graphics.RotateTransform(angle); //恢复绘图平面在水平和垂直方向的平移 graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y); //绘制图片 graphics.DrawImage(image, picRect); }
private void Dibujar(ref PictureBox pct, int x, int y, int width, int height, Color?color = null) { //Error de argumento en caso de no declararse un color if (color == null) { throw new ArgumentException("El color de pluma no fue especificado"); } //Error en caso que el ancho sea mayor a 349 if (width > 349) { throw new ArgumentException("El ancho rebasa el ancho del lienzo"); } //Error en caso que el largo sea mayor a 232 if (height > 232) { throw new ArgumentException("El ancho rebasa el ancho del lienzo"); } //En caso de especificar las dimensiones de 349 o 232 if (width == 349 | height == 232) { width -= 10; height -= 10; x = 0; y = 0; MessageBox.Show("Figura redimensionada para ser visible"); } Graphics papel; papel = pct.CreateGraphics(); Pen lapiz = new Pen(color.GetValueOrDefault()); papel.DrawRectangle(lapiz, x, y, width, height); }
private void UpdateImage() { if (bmp.Handle != IntPtr.Zero) //以下代码将原始图像数据用来进行图像! { Win32Api.CopyMemory((IntPtr)bmp.Pointer, (IntPtr)DataCopy, bmp.Stride * bmp.Height); } switch (filters) { case FiltersMethod.BoxBlur: BlurEffect.BoxBlur(bmp, (int)trbValue.Value); break; case FiltersMethod.Mosaic: BlurEffect.Mosaic(bmp, (int)trbValue.Value); break; } Graphics G = picPreview.CreateGraphics(); IntPtr Hdc = G.GetHdc(); bmp.DrawImage(Hdc, DestX, DestY, ViewWidth, ViewHeight, 0, 0, bmp.Width, bmp.Height); G.ReleaseHdc(); G.Dispose(); picPreview.Invalidate(); Graphics Gcanvas = canvas.CreateGraphics(); IntPtr canvasHdc = Gcanvas.GetHdc(); bmp.DrawImage(canvasHdc, 0, 0, canvas.Width, canvas.Height, 0, 0, bmp.Width, bmp.Height); Gcanvas.ReleaseHdc(); Gcanvas.Dispose(); canvas.Invalidate(); }
override public void Draw(PictureBox picture) { Graphics elem = picture.CreateGraphics(); Pen pen = new Pen(Pclr); elem.DrawLine(pen, x1, y1, x2, y2); }
/** * Default constructor for the dungeon draw class * @param DG the picture box to draw all the lovely graphics too */ public DungeonDraw(PictureBox DG) { Width = DG.Width; Height = DG.Height; PB = DG; G = DG.CreateGraphics(); }
static public void DrawOuterFrameCell(int cellX, int cellY, int color, Form form, PictureBox deckPictureBox) { Graphics g = deckPictureBox.CreateGraphics(); Pen framePen = new Pen(colors[color], 3); g.DrawRectangle(framePen, (cellX + 1) * 31 + -3, (cellY + 1) * 31 + -3, 37, 37); }
public void GetFonts() { LOGFONT lf = CreateLogFont(""); IntPtr plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf)); Marshal.StructureToPtr(lf, plogFont, true); int ret = 0; try { //If anyone knows of a better way to get the pointer please let me know var pictureBox = new PictureBox(); var graphic = pictureBox.CreateGraphics(); var ptr = graphic.GetHdc(); del1 = new EnumFontExDelegate(callback1); ret = EnumFontFamiliesEx(ptr, plogFont, del1, IntPtr.Zero, 0); System.Diagnostics.Trace.WriteLine("EnumFontFamiliesEx = " + ret.ToString()); graphic.ReleaseHdc(ptr); } catch { System.Diagnostics.Trace.WriteLine("Error!"); } finally { Marshal.DestroyStructure(plogFont, typeof(LOGFONT)); } }
public void Compile(PictureBox p) { Graphics g = p.CreateGraphics(); bool[] completed = new bool[ThreadCount]; int numCompleted = 0; for (int i = 0; i < ThreadCount; i++) completed[i] = false; while (numCompleted < ThreadCount) { for (int i = 0; i < ThreadCount; i++) { if (completed[i]) continue; if (Threads[i].IsAlive) continue; completed[i] = true; numCompleted++; PointF position = new PointF(i * PixelWidth, 0); Threads[i].Join(); g.DrawImage(RenderObjects[i].Production, position); } } Timer.Stop(); }