public System.Drawing.Bitmap KiRotate(System.Drawing.Bitmap bmp, float angle) { int w = bmp.Width + 2; int h = bmp.Height + 2; System.Drawing.Imaging.PixelFormat pf; pf = bmp.PixelFormat; System.Drawing.Bitmap tmp = new System.Drawing.Bitmap(w, h, pf); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(tmp); //g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(new System.Drawing.RectangleF(0f, 0f, w, h)); System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.Matrix(); mtrx.Rotate(angle); System.Drawing.RectangleF rct = path.GetBounds(mtrx); System.Drawing.Bitmap dst = new System.Drawing.Bitmap((int)rct.Width, (int)rct.Height, pf); g = System.Drawing.Graphics.FromImage(dst); //g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tmp, 0, 0); g.Dispose(); tmp.Dispose(); return(dst); }
public List <Point> ToPoints( float angle, Rectangle rect) { // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(rect); // Declare a matrix that will be used to rotate the text. System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F)); // Transform the text with the matrix. path.Transform(rotateMatrix); List <Point> results = new List <Point>(); foreach (PointF p in path.PathPoints) { results.Add(new Point((int)p.X, (int)p.Y)); } path.Dispose(); return(results); }
private void searchQueryPanel_Paint(object sender, PaintEventArgs e) { System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding); myGraphicsPath.AddEllipse(new Rectangle(707, 0, 44, 44)); myGraphicsPath.AddRectangle(new Rectangle(0, 0, 733, 44)); this.searchQueryPanel.Region = new Region(myGraphicsPath); }
private System.Drawing.Drawing2D.GraphicsPath RoundRegion(Rectangle r) { //Scale the radius if it's too large to fit. int radius = borderRadius; if (radius > (r.Width)) { radius = r.Width; } if (radius > (r.Height)) { radius = r.Height; } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (radius <= 0) { path.AddRectangle(r); } else { path.AddArc(r.Left, r.Top, radius, radius, 180, 90); path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90); path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90); path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90); path.CloseFigure(); } return(path); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.FillMode = System.Drawing.Drawing2D.FillMode.Winding; int height = TrackHeight / 5; int nBars = this.Width / BarSpacing; for (int bar = 0; bar < nBars; bar++) { gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, height, BarSpacing, height)); gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, height * 3, BarSpacing, height)); gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, 0, BarWith, TrackHeight)); } e.Graphics.FillPath(System.Drawing.Brushes.SaddleBrown, gp); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.FillMode = System.Drawing.Drawing2D.FillMode.Winding; int height = TrackHeight / 5; int nBars = this.Width / BarSpacing; for (int bar = 0; bar < nBars; bar++) { gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, height, BarSpacing, height)); gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, height * 3, BarSpacing, height)); gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, 0, BarWidth, TrackHeight)); } e.Graphics.FillPath(System.Drawing.Brushes.SaddleBrown, gp); }
//drawing transparent public static void Transparent(PictureBox pictureBox) { int x; int y; int alpha = 180; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pictureBox.Image); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); //System.Drawing.Color mask = bmp.GetPixel(0, 0); System.Drawing.Color mask = System.Drawing.Color.FromArgb(0, 0, 0, 0); //Program.Logger("DEBG", pictureBox.Name + " selected transparent color: " + mask.Name); for (x = 0; x <= bmp.Width - 1; x++) { for (y = 0; y <= bmp.Height - 1; y++) { //if (!bmp.GetPixel(x, y).Equals(mask)) { if (bmp.GetPixel(x, y).A > alpha) { gp.AddRectangle(new System.Drawing.Rectangle(x, y, 1, 1)); } } } //Program.Logger("DEBG", "alfa of color " + bmp.GetPixel(0,0).ToArgb() + " " + bmp.GetPixel(0, 0).A); pictureBox.Region = new System.Drawing.Region(gp); //clear bmp.Dispose(); }
void Command_Image_Rotate(ImageRotateDialog.Result result) { var variables = GetVariables(); var angle = new NEExpression(result.AngleExpression).Evaluate <float>(variables, "deg"); var bitmap = GetBitmap(); var path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height)); var matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Rotate(angle); var rect = path.GetBounds(matrix); var resultBitmap = new System.Drawing.Bitmap((int)rect.Width, (int)rect.Height, bitmap.PixelFormat); using (var g = System.Drawing.Graphics.FromImage(resultBitmap)) { g.TranslateTransform(-rect.X, -rect.Y); g.RotateTransform(angle); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(bitmap, 0, 0); } Replace(new List <Range> { FullRange }, new List <string> { Coder.BitmapToString(resultBitmap) }); SetSelections(new List <Range> { BeginRange }); }
public static System.Drawing.Drawing2D.GraphicsPath BuildTransparencyPath(PictureBox pb) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); Image im = pb.Image; int x; int y; if (pb.Image == null) { return(gp); } Bitmap bmp = new Bitmap(im); Color mask = bmp.GetPixel(0, 0); for (x = 0; x <= pb.Size.Width - 1; x++) { for (y = 0; y <= pb.Size.Height - 1; y++) { int newX = x * im.Size.Width / pb.Size.Width; int newY = y * im.Size.Height / pb.Size.Height; if (!bmp.GetPixel(newX, newY).Equals(mask)) { gp.AddRectangle(new Rectangle( x, y, 1, 1)); } } } bmp.Dispose(); return(gp); }
// Graphics methods //chuck's new code 2/20/04 //this method indicates whether point is along outline of graphic //and if so, what type of cursor should show public virtual void BoundaryTest(System.Drawing.Point pt, SizeDirection dir) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 3); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X - 3, this.m_Position.Y - 3, this.m_Size.Width + 6, this.m_Size.Height + 6)); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.X, (float)this.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); dir = SizeDirection.NA; if (gp.IsOutlineVisible(pt, pen)) { //user has placed the mouse along the outline of the selected //object - change the mouse to allow for resizing System.Drawing.RectangleF rect = gp.GetBounds(); if (Math.Abs((int)rect.Left - pt.X) <= 2) { if (Math.Abs((int)rect.Top - pt.Y) <= 2) { dir = SizeDirection.Northwest; } else if (Math.Abs((int)rect.Bottom - pt.Y) <= 2) { dir = SizeDirection.Southwest; } else { dir = SizeDirection.West; } } else if (Math.Abs((int)rect.Right - pt.X) <= 2) { if (Math.Abs((int)rect.Top - pt.Y) <= 2) { dir = SizeDirection.Northeast; } else if (Math.Abs((int)rect.Bottom - pt.Y) <= 2) { dir = SizeDirection.Southeast; } else { dir = SizeDirection.East; } } else if (Math.Abs((int)rect.Top - pt.Y) <= 2) { dir = SizeDirection.North; } else { dir = SizeDirection.South; } } }
protected override Region OnRegionRecreate() { using (var gp = new System.Drawing.Drawing2D.GraphicsPath()) { gp.AddRectangle(__primaryPrimitive.GetBounds()); return(new Region(gp)); } }
public static System.Drawing.Drawing2D.GraphicsPath GenerateSquarePath(System.Drawing.Rectangle rectangle) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddRectangle(rectangle); return(gp); }
/// <summary> /// サイズ変更イベント /// </summary> /// <param name="e"></param> protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); RectangleF rect = new RectangleF(0, 0, this.Width, this.Height); path.AddRectangle(rect); rect.X += FrameWidth; rect.Y += FrameWidth; rect.Width -= FrameWidth * 2; rect.Height -= FrameWidth * 2; path.AddRectangle(rect); this.Region = new Region(path); }
private void UpdateRegion() { System.Drawing.Drawing2D.GraphicsPath FormRegion = new System.Drawing.Drawing2D.GraphicsPath(); FormRegion.AddRectangle(new Rectangle(0, 0, this.Width, this.Height)); FormRegion.CloseAllFigures(); this.Region = new System.Drawing.Region(FormRegion); }
private void Form1_Load(object sender, EventArgs e) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(new Rectangle(0, 23, 155, 135)); this.Region = new Region(path); this.Location = new Point(0, 50); this.TopMost = true; this.timer1.Enabled = true; }
private void button1_Click(object sender, EventArgs e) { Point pt1 = new Point(R.Next(this.Width), R.Next(this.Height)); Point pt2 = new Point(R.Next(this.Width), R.Next(this.Height)); System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath(); shape.AddRectangle(new Rectangle(new Point(Math.Min(pt1.X, pt2.X), Math.Min(pt1.Y, pt2.Y)), new Size(Math.Abs(pt2.X - pt1.X), Math.Abs(pt2.Y - pt1.Y)))); Paths.Add(shape); this.Refresh(); }
private void MessageBox_Resize(object sender, EventArgs e) { AdjustDimensions(); MessageCtrl.Top = (this.Height / 2) - (MessageCtrl.Height / 2); MessageCtrl.Left = (this.Width / 2) - (MessageCtrl.Width / 2); System.Drawing.Drawing2D.GraphicsPath FormRegion = new System.Drawing.Drawing2D.GraphicsPath(); FormRegion.AddRectangle(new Rectangle(0, 0, this.Width, this.Height)); this.Region = new System.Drawing.Region(FormRegion); }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { var path = new System.Drawing.Drawing2D.GraphicsPath(); foreach (var item in _solution1.Items) { Rectangle rect = new Rectangle(new Point(item.X, item.Y), new Size(1, 1)); path.AddRectangle(rect); } e.Graphics.DrawPath(_pen, path); }
public void Form2_MouseMove(object sender, MouseEventArgs e) { //Debug.WriteLine("({0},{1})", e.X, e.Y); loc.X = nowLoc.X + 24 - Convert.ToInt32((double)e.X / 15.0f); loc.Y = nowLoc.Y + 14 - Convert.ToInt32((double)e.Y / 14.5f); this.Location = loc; System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath(); rectangle = new Rectangle(-loc.X + nowLoc.X + 24, -loc.Y + nowLoc.Y + 14, 720, 404); Debug.WriteLine("({0},{1})", loc.X, loc.Y); shape.AddRectangle(rectangle); this.Region = new Region(shape); }
private void ResizeRegion() { System.Drawing.Drawing2D.GraphicsPath grap = new System.Drawing.Drawing2D.GraphicsPath(); if (m_bShowTabNames) { grap.AddRectangle(new System.Drawing.Rectangle(0, 0, this.Width, this.Height)); } else { if (this.TabCount > 0) { System.Drawing.Rectangle recRegion = new System.Drawing.Rectangle(this.TabPages[0].Location.X, this.TabPages[0].Location.Y, this.TabPages[0].Width, this.TabPages[0].Height); grap.AddRectangle(recRegion); } else { grap.AddRectangle(new System.Drawing.Rectangle(0, 0, this.Width, this.Height)); } } this.Region = new System.Drawing.Region(grap); }
public override bool HitTest(System.Drawing.Point pt) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X - (int)(0.25 * this.m_Size.Width), this.m_Position.Y - (int)(0.25 * this.m_Size.Height), (int)(1.25 * this.m_Size.Width), (int)(1.25 * this.m_Size.Height))); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)(this.m_Rotation), new System.Drawing.PointF((float)this.X, (float)this.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); return(gp.IsVisible(pt)); }
public virtual bool HitTest(System.Drawing.Rectangle rect) {//is this object contained within the supplied rectangle System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X, this.m_Position.Y, this.m_Size.Width, this.m_Size.Height)); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.m_Position.X, (float)this.m_Position.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); System.Drawing.Rectangle gpRect = System.Drawing.Rectangle.Round(gp.GetBounds()); return(rect.Contains(gpRect)); }
private System.Drawing.Drawing2D.GraphicsPath GetRoundedRect(RectangleF baseRect, float radius) { // if corner radius is less than or equal to zero, // return the original rectangle if (radius <= 0.0F) { System.Drawing.Drawing2D.GraphicsPath mPath = new System.Drawing.Drawing2D.GraphicsPath(); mPath.AddRectangle(baseRect); mPath.CloseFigure(); return(mPath); } // if the corner radius is greater than or equal to // half the width, or height (whichever is shorter) // then return a capsule instead of a lozenge if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0) { return(GetCapsule(baseRect)); } // create the arc for the rectangle sides and declare // a graphics path object for the drawing float diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(baseRect.Location, sizeF); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = baseRect.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); }
private void btnQuadrado_Click(object sender, EventArgs e) { try { if (byte.Parse(mtxtLinhas.Text) < 9) { byte linhas = byte.Parse(mtxtLinhas.Text); int aux = 0; foreach (Panel A in Paineis) { A.Visible = false; } foreach (Control CON in this.Controls) { if (CON.GetType() == typeof(Panel)) { foreach (Label Lab in CON.Controls) { var path = new System.Drawing.Drawing2D.GraphicsPath(); Rectangle pathRect = new Rectangle(0, 0, Lab.Width, Lab.Height); path.AddRectangle(pathRect); Lab.Region = new Region(path); } } } foreach (Panel A in Paineis) { if (aux == Convert.ToInt32(mtxtLinhas.Text)) { break; } A.Visible = true; aux++; } } else { MessageBox.Show("Digite um valor válido!"); } } catch { MessageBox.Show("Digite um valor válido!"); } }
static System.Drawing.Drawing2D.GraphicsPath BuildTransparentPath(Bitmap bmp) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); Color mask = Color.FromArgb(0, 0, 0, 0); for (int i = 0; i < bmp.Width; i++) { for (int j = 0; j < bmp.Height; j++) { if (!bmp.GetPixel(i, j).Equals(mask)) { gp.AddRectangle(new Rectangle(i, j, 1, 1)); } } } return(gp); }
public CustomRect(int x, int y, int width, Color color) { InitializeComponent(); this.Data = new XData(); this.Data.PointX = x; this.Data.PointY = y; this.Data.SizeX = width; this.Data.SizeY = width; this.Data.Width = width; this.Data.Color = color; System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath(); Button_Path.AddRectangle(new System.Drawing.Rectangle(this.Data.PointX, this.Data.PointY, this.Data.SizeX, this.Data.SizeY)); Region Button_Region = new Region(Button_Path); this.Region = Button_Region; Graphics g = this.CreateGraphics(); OnPaint(new PaintEventArgs(g, new System.Drawing.Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height))); }
public void DrawRect(int[] data) { Debug.WriteLine(data); Point min = scaledPoint(new Point(data[0], data[1])); Point max = scaledPoint(new Point(data[2], data[3])); Debug.WriteLine(min); Debug.WriteLine(max); Rectangle rect = new Rectangle(min.X, min.Y, max.X - min.X, max.Y - min.Y); vehiclePath.Reset(); vehiclePath.AddRectangle(rect); speedPath.AddString(data[4].ToString() + " kmh", System.Drawing.FontFamily.GenericSansSerif, 0, 18, new Point(min.X, min.Y - 18), StringFormat.GenericDefault); pictureBox.Invalidate(); }
/// <summary> /// 確定前のタイルを描画 /// </summary> protected virtual void drawTemporaryTiles() { DX.SetDrawBlendMode(DX.DX_BLENDMODE_NOBLEND, -1); if (this.parent.PuttingTileStart != null) { //実際の描画領域を生成する var tempPath = new System.Drawing.Drawing2D.GraphicsPath(); switch (this.parent.EditMode) { case mgrMapObject.TileEditMode.Rectangle: tempPath.AddRectangle(this.parent.PuttingTileRange); break; case mgrMapObject.TileEditMode.Ellipse: tempPath.AddEllipse(this.parent.PuttingTileRange.X - 1, this.parent.PuttingTileRange.Y - 1, this.parent.PuttingTileRange.Width + 1, this.parent.PuttingTileRange.Height + 1); break; } //確定前のタイルを描画する for (int a = 0, x = this.parent.PuttingTileRange.Left; x < this.parent.PuttingTileRange.Right; x++, a++) { for (int b = 0, y = this.parent.PuttingTileRange.Top; y < this.parent.PuttingTileRange.Bottom; y++, b++) { if (!tempPath.IsVisible(x, y)) { //描画領域に該当しない部分はスキップする continue; } //単一タイルを描画 if (this.parent.ClippingTiles != null) { //クリッピングしている場合 this.drawTileWithAutotilePattern(x, y, this.parent.ClippingTiles[a % this.parent.ClippingTiles.GetLength(0), b % this.parent.ClippingTiles.GetLength(1)].PalletPosition, Map.AutoTilePattern.AllSide); } else { //パレットで選択している場合 this.drawTileWithAutotilePattern(x, y, new Point((this.parent.SelectedPalletRange.Location.X + (a % this.parent.SelectedPalletRange.Width)), (this.parent.SelectedPalletRange.Location.Y + (b % this.parent.SelectedPalletRange.Height))), Map.AutoTilePattern.AllSide); } } } } }
public UIElement GetHitElement(System.Drawing.Point hittedPoint) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); Shape temp; for (int i = canvas.Children.Count - 1; i >= 0; i--) { temp = (Shape)canvas.Children[i]; System.Drawing.Size childSize = new System.Drawing.Size((int)temp.Width, (int)temp.Height); System.Drawing.Point childPos = new System.Drawing.Point(); childPos.X = (int)canvas.Children[i].TranslatePoint(new System.Windows.Point(0, 0), canvas).X; childPos.Y = (int)canvas.Children[i].TranslatePoint(new System.Windows.Point(0, 0), canvas).Y; path.AddRectangle(new System.Drawing.Rectangle(childPos, childSize)); if (path.IsVisible(hittedPoint)) { return(canvas.Children[i]); } } return(null); }
private System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle r, int radius, Corners corners) { //Make sure the Path fits inside the rectangle r.Width -= 1; r.Height -= 1; //Scale the radius if it's too large to fit. if (radius > (r.Width)) radius = r.Width; if (radius > (r.Height)) radius = r.Height; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (radius <= 0) path.AddRectangle(r); else if ((corners & Corners.TopLeft) == Corners.TopLeft) path.AddArc(r.Left, r.Top, radius, radius, 180, 90); else path.AddLine(r.Left, r.Top, r.Left, r.Top); if ((corners & Corners.TopRight) == Corners.TopRight) path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90); else path.AddLine(r.Right, r.Top, r.Right, r.Top); if ((corners & Corners.BottomRight) == Corners.BottomRight) path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90); else path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom); if ((corners & Corners.BottomLeft) == Corners.BottomLeft) path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90); else path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom); path.CloseFigure(); return path; }
public static System.Drawing.Drawing2D.GraphicsPath Transparent(Image im) { int x; int y; var bmp = new Bitmap(im); var gp = new System.Drawing.Drawing2D.GraphicsPath(); var mask = bmp.GetPixel(0, 0); for (x = 0; x <= bmp.Width - 1; x++) { for (y = 0; y <= bmp.Height - 1; y++) { if (!bmp.GetPixel(x, y).Equals(mask)) { gp.AddRectangle(new Rectangle(x, y, 1, 1)); } } } bmp.Dispose(); return gp; }
private void updateShape(object sender, InvalidateEventArgs e) { if (this.Image = null) { return; } Bitmap bitmap = new Bitmap(this.Image); System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); for (int x = 0; x < this.Image.Width; x++) { for (int y = 0; y < this.Image.Height; y++) { if (transparentColor != bitmap.GetPixel(x, y)) { graphicsPath.AddRectangle(new Rectangle(new Point(x, y), new Size(1, 1))); } } } this.Region = new Region(graphicsPath); }
static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path) { //convert from graphics path to internal presentation System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath; if (innerPath != null) { return innerPath; } //-------- innerPath = new System.Drawing.Drawing2D.GraphicsPath(); path.InnerPath = innerPath; List<float> points; List<PathCommand> cmds; GraphicsPath.GetPathData(path, out points, out cmds); int j = cmds.Count; int p_index = 0; for (int i = 0; i < j; ++i) { PathCommand cmd = cmds[i]; switch (cmd) { default: throw new NotSupportedException(); case PathCommand.Arc: innerPath.AddArc( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3], points[p_index + 4], points[p_index + 5]); p_index += 6; break; case PathCommand.Bezier: innerPath.AddBezier( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3], points[p_index + 4], points[p_index + 5], points[p_index + 6], points[p_index + 7]); p_index += 8; break; case PathCommand.CloseFigure: innerPath.CloseFigure(); break; case PathCommand.Ellipse: innerPath.AddEllipse( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3]); p_index += 4; break; case PathCommand.Line: innerPath.AddLine( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3]); p_index += 4; break; case PathCommand.Rect: innerPath.AddRectangle( new System.Drawing.RectangleF( points[p_index], points[p_index + 1], points[p_index + 2], points[p_index + 3])); p_index += 4; break; case PathCommand.StartFigure: break; } } return innerPath; }
public List<Point> ToPoints( float angle, Rectangle rect) { // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(rect); // Declare a matrix that will be used to rotate the text. System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F)); // Transform the text with the matrix. path.Transform(rotateMatrix); List<Point> results = new List<Point>(); foreach(PointF p in path.PathPoints) { results.Add(new Point((int)p.X, (int)p.Y)); } path.Dispose(); return results; }
/// <summary> /// Draws labels in a specified rectangle /// </summary> /// <param name="g">The graphics object to draw to</param> /// <param name="labelText">The label text to draw</param> /// <param name="labelBounds">The rectangle of the label</param> /// <param name="symb">the Label Symbolizer to use when drawing the label</param> private static void DrawLabel(Graphics g, string labelText, RectangleF labelBounds, ILabelSymbolizer symb) { //Sets up the brushes and such for the labeling Brush foreBrush = new SolidBrush(symb.FontColor); Font textFont = symb.GetFont(); StringFormat format = new StringFormat(); format.Alignment = symb.Alignment; Pen borderPen = new Pen(symb.BorderColor); Brush backBrush = new SolidBrush(symb.BackColor); Brush haloBrush = new SolidBrush(symb.HaloColor); Pen haloPen = new Pen(symb.HaloColor); haloPen.Width = 2; haloPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Outset; Brush shadowBrush = new SolidBrush(symb.DropShadowColor); //Text graphics path System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddString(labelText, textFont.FontFamily, (int)textFont.Style, textFont.SizeInPoints * 96F / 72F, labelBounds, format); //Draws the text outline if (symb.BackColorEnabled && symb.BackColor != Color.Transparent) { if (symb.FontColor == Color.Transparent) { System.Drawing.Drawing2D.GraphicsPath backgroundGP = new System.Drawing.Drawing2D.GraphicsPath(); backgroundGP.AddRectangle(labelBounds); backgroundGP.FillMode = System.Drawing.Drawing2D.FillMode.Alternate; backgroundGP.AddPath(gp, true); g.FillPath(backBrush, backgroundGP); backgroundGP.Dispose(); } else { g.FillRectangle(backBrush, labelBounds); } } //Draws the border if its enabled if (symb.BorderVisible && symb.BorderColor != Color.Transparent) g.DrawRectangle(borderPen, labelBounds.X, labelBounds.Y, labelBounds.Width, labelBounds.Height); //Draws the drop shadow if (symb.DropShadowEnabled && symb.DropShadowColor != Color.Transparent) { System.Drawing.Drawing2D.Matrix gpTrans = new System.Drawing.Drawing2D.Matrix(); gpTrans.Translate(symb.DropShadowPixelOffset.X, symb.DropShadowPixelOffset.Y); gp.Transform(gpTrans); g.FillPath(shadowBrush, gp); gpTrans = new System.Drawing.Drawing2D.Matrix(); gpTrans.Translate(-symb.DropShadowPixelOffset.X, -symb.DropShadowPixelOffset.Y); gp.Transform(gpTrans); } //Draws the text halo if (symb.HaloEnabled && symb.HaloColor != Color.Transparent) g.DrawPath(haloPen, gp); //Draws the text if its not transparent if (symb.FontColor != Color.Transparent) g.FillPath(foreBrush, gp); //Cleans up the rest of the drawing objects shadowBrush.Dispose(); borderPen.Dispose(); foreBrush.Dispose(); backBrush.Dispose(); haloBrush.Dispose(); haloPen.Dispose(); }
protected System.Drawing.Drawing2D.GraphicsPath GetPath() { System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath(); if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) { graphPath.AddRectangle(this.ClientRectangle); } else { try { int curve = 0; System.Drawing.Rectangle rect = this.ClientRectangle; int offset = 0; if (this._BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle) { if (this._BorderWidth > 1) { offset = DoubleToInt(this.BorderWidth / 2); } curve = this.adjustedCurve; } else if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) { } else if (this._BorderStyle == System.Windows.Forms.BorderStyle.None) { curve = this.adjustedCurve; } if (curve == 0) { graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset)); } else { int rectWidth = rect.Width - 1 - offset; int rectHeight = rect.Height - 1 - offset; int curveWidth = 1; if ((this._CurveMode & CornerCurveMode.TopRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90); if ((this._CurveMode & CornerCurveMode.BottomRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90); if ((this._CurveMode & CornerCurveMode.BottomLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90); if ((this._CurveMode & CornerCurveMode.TopLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90); graphPath.CloseFigure(); } } catch (System.Exception) { graphPath.AddRectangle(this.ClientRectangle); } } return graphPath; }
/// <summary> /// Creates a rounded corner rectangle from a regular rectangel /// </summary> /// <param name="baseRect"></param> /// <param name="radius"></param> /// <returns></returns> private System.Drawing.Drawing2D.GraphicsPath GetRoundedRect(RectangleF baseRect, float radius) { if ((radius <= 0.0F) || radius >= ((Math.Min(baseRect.Width, baseRect.Height)) / 2.0)) { System.Drawing.Drawing2D.GraphicsPath mPath = new System.Drawing.Drawing2D.GraphicsPath(); mPath.AddRectangle(baseRect); mPath.CloseFigure(); return mPath; } float diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(baseRect.Location, sizeF); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = baseRect.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return path; }
protected override void GeneratePath() { _Path = new System.Drawing.Drawing2D.GraphicsPath(); _Path.AddRectangle(new Rectangle(Location, Size)); InvalidationArea = Rectangle.Round(_Path.GetBounds()); }
private void updateBorder() { var imeInfo = _monitor.IMEStatus; _lastImeStatus = imeInfo; if (imeInfo.WindowHandle == this.Handle || !imeInfo.WindowVisible || imeInfo.Ignored) { this.Opacity = 0f; setTopMost(false); } else { var borderWidth = imeInfo.IMEEnabled ? _settings.ImeOnBorderStyle.Width : _settings.ImeOffBorderStyle.Width; Rectangle windowRect = imeInfo.ClientBounds; windowRect.Inflate(borderWidth, borderWidth); // スクリーン外にはみ出た部分を押し込む Rectangle screenRect = Screen.FromHandle(imeInfo.ClientHandle).Bounds; { int left = windowRect.X; int top = windowRect.Y; int right = windowRect.Right; int bottom = windowRect.Bottom; if (left < screenRect.X) left = screenRect.X; if (top < screenRect.Y) top = screenRect.Y; if (right > screenRect.Right) right = screenRect.Right; if (bottom > screenRect.Bottom) bottom = screenRect.Bottom; windowRect = Rectangle.FromLTRB(left, top, right, bottom); } if (this.Size == windowRect.Size) { this.Location = windowRect.Location; } else { var path = new System.Drawing.Drawing2D.GraphicsPath(); var w = windowRect.Width; var h = windowRect.Height; var border2x = borderWidth * 2; path.AddPie(0, 0, border2x, border2x, 180, 90); path.AddPie(w - border2x, 0, border2x, border2x, 270, 90); path.AddPie(0, h - border2x, border2x, border2x, 90, 90); path.AddPie(w - border2x, h - border2x, border2x, border2x, 0, 90); path.AddRectangle(new Rectangle(0, borderWidth, borderWidth, h - border2x)); path.AddRectangle(new Rectangle(borderWidth, 0, w - border2x, borderWidth)); path.AddRectangle(new Rectangle(w - borderWidth, borderWidth, borderWidth, h - border2x)); path.AddRectangle(new Rectangle(borderWidth, h - borderWidth, w - border2x, borderWidth)); this.Region = new Region(path); this.Bounds = windowRect; } this.BackColor = imeInfo.IMEEnabled ? _settings.ImeOnBorderStyle.GetColor() : _settings.ImeOffBorderStyle.GetColor(); this.Opacity = imeInfo.IMEEnabled ? _settings.ImeOnBorderStyle.Opacity : _settings.ImeOffBorderStyle.Opacity; setTopMost(true); } }
/// <summary> /// Converts this structure to a GraphicsPath object, used to draw to a Graphics device. /// Consider that you can create a Region with a GraphicsPath object using one of the Region constructor. /// </summary> /// <returns></returns> public System.Drawing.Drawing2D.GraphicsPath ToGraphicsPath() { if (mRectangle.IsEmpty) return new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); if (mRoundValue == 0) { //Remove 1 from height and width to draw the border in the right location //path.AddRectangle(new Rectangle(new Point(mRectangle.X - 1, mRectangle.Y - 1), mRectangle.Size)); path.AddRectangle(mRectangle); } else { int x = mRectangle.X; int y = mRectangle.Y; int lineShift = 0; int lineShiftX2 = 0; //Basically the RoundValue is a percentage of the line to curve, so I simply multiply it with the lower side (height or width) if (mRectangle.Height < mRectangle.Width) { lineShift = (int)((double)mRectangle.Height * mRoundValue); lineShiftX2 = lineShift * 2; } else { lineShift = (int)((double)mRectangle.Width * mRoundValue); lineShiftX2 = lineShift * 2; } //Top path.AddLine(lineShift + x, 0 + y, (mRectangle.Width - lineShift) + x, 0 + y); //Angle Top Right path.AddArc((mRectangle.Width - lineShiftX2) + x, 0 + y, lineShiftX2, lineShiftX2, 270, 90); //Right path.AddLine(mRectangle.Width + x, lineShift + y, mRectangle.Width + x, (mRectangle.Height - lineShift) + y); //Angle Bottom Right path.AddArc((mRectangle.Width - lineShiftX2) + x, (mRectangle.Height - lineShiftX2) + y, lineShiftX2, lineShiftX2, 0, 90); //Bottom path.AddLine((mRectangle.Width - lineShift) + x, mRectangle.Height + y, lineShift + x, mRectangle.Height + y); //Angle Bottom Left path.AddArc(0 + x, (mRectangle.Height - lineShiftX2) + y, lineShiftX2, lineShiftX2, 90, 90); //Left path.AddLine(0 + x, (mRectangle.Height - lineShift) + y, 0 + x, lineShift + y); //Angle Top Left path.AddArc(0 + x, 0 + y, lineShiftX2, lineShiftX2, 180, 90); } return path; }