Esempio n. 1
0
        // Call to paint the grid itself
        public void Paint(System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;
            System.Drawing.Pen      p = new System.Drawing.Pen(System.Drawing.Color.Black, 1); // outline
            System.Drawing.Brush    b;

            // draw the filled-in grid
            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    b = new System.Drawing.SolidBrush(grid[x, y].Color);
                    System.Drawing.Rectangle rect =
                        new System.Drawing.Rectangle(grid[x, y].X + this.shift_x, grid[x, y].Y + this.shift_y,
                                                     scale, scale);

                    g.FillRectangle(b, rect);
                    g.DrawRectangle(p, rect);
                }
            }

            if (game_end)
            {
                foreach (GridBlock gb in this.overflow)
                {
                    b = new System.Drawing.SolidBrush(gb.Color);
                    System.Drawing.Rectangle rect =
                        new System.Drawing.Rectangle(gb.X + this.shift_x, gb.Y + this.shift_y,
                                                     scale, scale);

                    g.FillRectangle(b, rect);
                    g.DrawRectangle(p, rect);
                }
            }
            else
            {
                Tetromino f = this.minos.First();
                b = new System.Drawing.SolidBrush(f.Color);
                foreach (System.Drawing.Rectangle r in f.GetRectangles(this.shift_x, this.shift_y))
                {
                    g.FillRectangle(b, r);
                    g.DrawRectangle(p, r);
                }
            }

            int x_shift = this.shift_x + 12 * this.scale;
            int y_shift = this.shift_y + 3 * this.scale;

            for (int i = 1; i < 4; i++)
            {
                Tetromino t = this.minos.ElementAt(i);
                b = new System.Drawing.SolidBrush(t.Color);
                foreach (System.Drawing.Rectangle r in t.GetRectangles(x_shift, y_shift))
                {
                    g.FillRectangle(b, r);
                    g.DrawRectangle(p, r);
                }
                y_shift += 5 * this.scale;
            }
        }
Esempio n. 2
0
 public override void DrawRectangle(int x, int y, int width, int height, Color color)
 {
     using (var pen = new System.Drawing.Pen(color.GetColor()))
     {
         x += transX;
         y += transY;
         var rect = new System.Drawing.Rectangle(x, y, width - 1, height - 1);
         gfx.DrawRectangle(pen, rect);
     }
 }
Esempio n. 3
0
        public void redraw()
        {
            drawcnt++;
            if (drawcnt < DRAWINTERVAL)
            {
                return;
            }
            drawcnt = 0;

            if (this.Image.Width != this.Width || this.Image.Height != this.Height)
            {
                System.Drawing.Bitmap img = new System.Drawing.Bitmap(this.Width, this.Height);
                this.Image = img;
                g          = System.Drawing.Graphics.FromImage(img);
            }

            if (!isGameOver())
            {
                int cellWidth  = this.Width / cellsY;
                int cellHeight = this.Height / cellsY;
                g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.White), new System.Drawing.Rectangle(0, 0, this.Width, this.Height));
                System.Drawing.Brush head = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                System.Drawing.Brush rest = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
                for (int i = snake.Length - 1; i >= 0; i--)
                {
                    g.FillRectangle(i == 0 ? head : rest, new System.Drawing.Rectangle(snake[i].X * cellWidth, snake[i].Y * cellHeight, cellWidth, cellHeight));
                }
                System.Drawing.Brush foodB = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                g.FillRectangle(foodB, new System.Drawing.Rectangle(food.X * cellWidth, food.Y * cellHeight, cellWidth, cellHeight));

                g.DrawRectangle(System.Drawing.Pens.DarkGray, new System.Drawing.Rectangle(0, 0, this.Width - 1, this.Height - 1));
            }
            else
            {
                int cellWidth  = this.Width / cellsY;
                int cellHeight = this.Height / cellsY;
                g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.LightGray), new System.Drawing.Rectangle(0, 0, this.Width, this.Height));
                int v = 0;
                foreach (System.Drawing.Point p in recordedpath)
                {
                    System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, v));
                    if (v < 255)
                    {
                        v += 10; if (v > 255)
                        {
                            v = 255;
                        }
                    }
                    g.FillRectangle(b, new System.Drawing.Rectangle(p.X * cellWidth, p.Y * cellHeight, cellWidth, cellHeight));
                    System.Drawing.Brush foodB = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                    g.FillRectangle(foodB, new System.Drawing.Rectangle(food.X * cellWidth, food.Y * cellHeight, cellWidth, cellHeight));
                    g.DrawRectangle(System.Drawing.Pens.DarkGray, new System.Drawing.Rectangle(0, 0, this.Width - 1, this.Height - 1));
                }
            }
        }
Esempio n. 4
0
        internal void Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;
            g.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);

            float xMod       = g.VisibleClipBounds.Width / 100;
            float yMod       = g.VisibleClipBounds.Height / 60;
            float playerSize = ServerParam.Instance.Player_size * 2 * 5;
            float ballSize   = ServerParam.Instance.Ball_size * 2 * 10;

            System.Drawing.Pen pen  = new System.Drawing.Pen(System.Drawing.Brushes.White, xMod);
            System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.LightBlue, xMod); //added
            g.DrawLine(pen, xMod * 50, 0, xMod * 50, yMod * 60);
            g.DrawRectangle(pen, new System.Drawing.Rectangle((int)(xMod * 92), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14)));
            g.DrawRectangle(pen, new System.Drawing.Rectangle((int)(xMod * -5), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14)));
            g.DrawRectangle(pen2, new System.Drawing.Rectangle((int)(xMod * 43), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14)));//added
            g.DrawEllipse(pen, new System.Drawing.Rectangle((int)(xMod * 43), (int)(yMod * 23), (int)(xMod * 14), (int)(yMod * 14)));
            RoboCup.Geometry.Vector pos1    = new Vector(0, 0);
            RoboCup.Geometry.Vector pos2    = new Vector(0, 0);
            System.Drawing.Pen      linePen = new System.Drawing.Pen(System.Drawing.Brushes.Black, xMod);
            for (int i = 0; i < DrawPlayerList.Count; i++)
            {
                Player p = DrawPlayerList[i];
                pos1.X = (p.Position.X + 50) * xMod;
                pos2.X = (p.Position.X + 50) * xMod;
                pos1.Y = (p.Position.Y + 30) * yMod;
                pos2.Y = (p.Position.Y + 30) * yMod;

                pos1.X += (float)(Math.Cos(p.AngleBodyCommitted) * xMod * playerSize / 2);
                pos1.Y += (float)(Math.Sin(p.AngleBodyCommitted) * yMod * playerSize / 2);
                pos2.X -= (float)(Math.Cos(p.AngleBodyCommitted) * xMod * playerSize / 2);
                pos2.Y -= (float)(Math.Sin(p.AngleBodyCommitted) * yMod * playerSize / 2);


                g.FillEllipse(p.Side == "l"?System.Drawing.Brushes.Blue:p.Side == "r"?System.Drawing.Brushes.Red:System.Drawing.Brushes.Yellow, new System.Drawing.Rectangle(new System.Drawing.Point((int)Math.Round((p.Position.X + 50 - playerSize / 2) * xMod, (int)MidpointRounding.AwayFromZero), (int)Math.Round((p.Position.Y + 30 - playerSize / 2) * yMod, MidpointRounding.AwayFromZero)), new System.Drawing.Size((int)(playerSize * xMod), (int)(playerSize * yMod))));
                g.DrawLine(linePen, pos1.X, pos1.Y, pos2.X, pos2.Y);
            }

            foreach (var b in Balls)
            {
                if (b != null)
                {
                    g.FillEllipse(System.Drawing.Brushes.Gray, new System.Drawing.Rectangle(new System.Drawing.Point((int)Math.Round((b.Position.X + 50 - ballSize / 2) * xMod, (int)MidpointRounding.AwayFromZero), (int)Math.Round((b.Position.Y + 30 - ballSize / 2) * yMod, MidpointRounding.AwayFromZero)), new System.Drawing.Size((int)(ballSize * xMod), (int)(ballSize * yMod))));
                }
            }

            foreach (Referee r in Referees)
            {
                r.doPaint(sender, e);
            }
        }
Esempio n. 5
0
        private void DrawRectangle(bool draw)
        {
            System.Drawing.Graphics gr = System.Drawing.Graphics.FromHwnd(Handle);
            System.Drawing.Pen      p  = null;
            if (IsRectVisible || !draw)  //erase the rect
            {
                int r = View.GetBGColR();
                int g = View.GetBGColG();
                int b = View.GetBGColB();
                p             = new System.Drawing.Pen(System.Drawing.Color.FromArgb(r, g, b));
                IsRectVisible = false;
                View.UpdateView();
            }
            else if (draw)
            {
                p             = new System.Drawing.Pen(System.Drawing.Color.White);
                IsRectVisible = true;
            }
            if (p == null)
            {
                return;
            }
            int x = Math.Min(myXmin, myXmax);
            int y = Math.Min(myYmin, myYmax);

            gr.DrawRectangle(p, x, y, Math.Abs(myXmax - myXmin), Math.Abs(myYmax - myYmin));
            myRectDownX = Math.Max(myXmin, myXmax);
            myRectDownY = Math.Max(myYmin, myYmax);
        }
Esempio n. 6
0
 public void  paint(System.Drawing.Graphics g, System.Windows.Forms.Control c)
 {
     //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Graphics.getFont' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
     System.Drawing.Font font    = SupportClass.GraphicsManager.manager.GetFont(g);
     System.Drawing.Font metrics = SupportClass.GraphicsManager.manager.GetFont(g);
     //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
     //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean'"
     System.Drawing.Text.TextRenderingHint frc = TextRenderingHint.AntiAlias; //  new FontRenderContext(null, false, false);
     System.Drawing.Size size = c.Size;
     SupportClass.GraphicsManager.manager.SetColor(g, c.BackColor);
     g.FillRectangle(SupportClass.GraphicsManager.manager.GetPaint(g), 0, 0, size.Width, size.Height);
     SupportClass.GraphicsManager.manager.SetColor(g, c.ForeColor);
     g.DrawRectangle(SupportClass.GraphicsManager.manager.GetPen(g), 0, 0, size.Width - 1, size.Height - 1);
     if (strs != null)
     {
         int y = 0;
         for (int i = 0; i < strs.Length; i++)
         {
             // TODO: use render hint? frc
             y += (int)g.MeasureString(strs[i], font).Height + 2;
             //UPGRADE_TODO: Method 'java.awt.Graphics.drawString' was converted to 'System.Drawing.Graphics.DrawString' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtGraphicsdrawString_javalangString_int_int'"
             g.DrawString(strs[i], SupportClass.GraphicsManager.manager.GetFont(g), SupportClass.GraphicsManager.manager.GetBrush(g), 3, y - SupportClass.GraphicsManager.manager.GetFont(g).GetHeight());
             //g.drawString(strs[i],3,(metrics.getHeight())*(i+1));
         }
     }
 }
Esempio n. 7
0
        public static System.Drawing.Bitmap GetBitmap(System.Drawing.Color color)
        {
            int size = 16;

            System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)myImages[color];
            if (bmp != null)
            {
                return(bmp);
            }
            bmp = new System.Drawing.Bitmap(size, size);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(color))
                {
                    g.FillRectangle(b, 3, 3, size - 6, size - 6);
                }
                g.DrawRectangle(System.Drawing.Pens.Black, 3, 3, size - 6, size - 6);

                //g.Clear(color);
                //g.DrawRectangle(System.Drawing.Pens.Black, 0, 0, 14, 14);
            }
            //bmp.MakeTransparent(System.Drawing.Color.Transparent);
            myImages[color] = bmp;
            return(bmp);
        }
Esempio n. 8
0
        /// <summary>
        /// Draw round rectangle
        /// </summary>
        /// <param name="roundRectangle"></param>
        /// <returns></returns>
        private string DrawRoundRectangle(DocumentFormat.OpenXml.Vml.RoundRectangle roundRectangle)
        {
            string fileName   = Path.Combine(imageDirectory, roundRectangle.GetAttributes().Where(x => x.LocalName == "id").FirstOrDefault().Value + ".jpg");
            string style      = roundRectangle.GetAttributes().Where(x => x.LocalName == "style").FirstOrDefault().Value;
            string position   = GetValueOfProperty("position", style);
            int    marginLeft = ConvertPointToPixel(GetValueOfProperty("margin-left", style));
            int    marginTop  = ConvertPointToPixel(GetValueOfProperty("margin-top", style));
            int    width      = ConvertPointToPixel(GetValueOfProperty("width", style));
            int    height     = ConvertPointToPixel(GetValueOfProperty("height", style));

            System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height);

            using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(newBmp))
            {
                System.Drawing.Pen pen = new System.Drawing.Pen(ConvertToColor(roundRectangle.StrokeColor.Value), ConvertPointToPixel(roundRectangle.StrokeWeight.Value));
                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                System.Drawing.SolidBrush solidBrush = new System.Drawing.SolidBrush(ConvertToColor(roundRectangle.FillColor.Value));
                System.Drawing.Rectangle  rectangle  = new System.Drawing.Rectangle(0, 0, width, height);
                graphic.FillRectangle(solidBrush, rectangle);
                graphic.DrawRectangle(pen, rectangle);
            }
            newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

            return(string.Format("<span style='position:{0};margin-left:{1}px;margin-top:{2}px;width:{3}px;height:{4}px'><img width=\"{3}\" height=\"{4}\" alt=\"{5}\" src=\"{6}\"/>",
                                 position, marginLeft, marginTop, width, height, Path.GetFileName(fileName), Util.GetRelativePath(fileName)));
        }
Esempio n. 9
0
 /// <summary>
 /// 产生验证码图片二进制流
 /// </summary>
 /// <param name="CodeLength">验证码长度</param>
 /// <param name="InputImageWidth">图片宽度</param>
 /// <param name="InputImageHeight">图片高度</param>
 /// <param name="VelidateCode">验证码的真实值</param>
 public static byte[] CreateValidateCode(int CodeLength, int InputImageWidth, int InputImageHeight, out string VelidateCode)
 {
     VelidateCode = GenerateRandomChareNumString(CodeLength);
     byte[] reVal = null;
     #region 画出验证码
     System.Drawing.Bitmap   image = new System.Drawing.Bitmap(InputImageWidth, InputImageHeight);
     System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
     try
     {
         System.Random random = new Random();
         g.Clear(System.Drawing.Color.White);
         System.Drawing.Font font = new System.Drawing.Font("Microsoft Yahei", 16, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
         System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 1.2f, true);
         g.DrawString(VelidateCode, font, brush, 2, 2);
         for (int i = 0; i < InputImageWidth * InputImageHeight / 5; i++)
         {
             int x = random.Next(image.Width);
             int y = random.Next(image.Height);
             image.SetPixel(x, y, System.Drawing.Color.FromArgb(random.Next()));
         }
         g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Black), 0, 0, image.Width - 1, image.Height - 1);
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
         reVal = ms.ToArray();
         return(reVal);
     }
     finally
     {
         g.Dispose();
         image.Dispose();
     }
     #endregion 画出验证码
 }
Esempio n. 10
0
        public override void Draw(System.Drawing.Graphics g)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }

            if (base.Dragging)
            {
                System.Drawing.Rectangle rectangle = GetViewportRectangle();

                if (base.Brush != null)
                {
                    System.Drawing.Drawing2D.Matrix prevBrushMatrix = PathVObjectCreateDesigner.AdaptBrushToViewport(base.Brush, this.VObjectHost.HostViewer);
                    try
                    {
                        g.FillRectangle(base.Brush, rectangle);
                    }
                    finally
                    {
                        if (prevBrushMatrix != null)
                        {
                            VObjectsUtils.SetBrushMatrix(base.Brush, prevBrushMatrix);
                        }
                    }
                }

                if (base.Pen != null)
                {
                    using (System.Drawing.Pen pen = CreateViewportPen())
                        g.DrawRectangle(pen, rectangle);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Renders a captured image along with recognized contours
        /// </summary>
        private void DrawConturs(ContourFilter processor, System.Drawing.Bitmap imageBuffer)
        {
            System.Drawing.Font font = new System.Drawing.Font("Arial", 24);
            // visual style of contours and labels
            System.Drawing.Brush bgBrush   = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0));
            System.Drawing.Brush foreBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 255, 255, 255));
            System.Drawing.Pen   borderPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, 0, 0, 255));
            borderPen.Width = 5;

            // we use double buffer -> the rendering will take its place once the image is ready
            System.Drawing.Graphics grBuffer = System.Drawing.Graphics.FromImage(imageBuffer);
            grBuffer.ScaleTransform((float)(width / 640), (float)((height - 20) / 480));
            foreach (FoundTemplateDesc found in processor.foundTemplates)
            {
                // draw detected contours along with their name and wrapping rectangle
                System.Drawing.Rectangle foundRect = found.sample.contour.SourceBoundingRect;
                System.Drawing.Point     p1        = new System.Drawing.Point((foundRect.Left + foundRect.Right) / 2, foundRect.Top);
                string text = found.template.name;

                grBuffer.DrawRectangle(borderPen, foundRect);
                grBuffer.DrawString(text, font, bgBrush, new System.Drawing.PointF(p1.X + 1 - font.Height / 3, p1.Y + 1 - font.Height));
                grBuffer.DrawString(text, font, foreBrush, new System.Drawing.PointF(p1.X - font.Height / 3, p1.Y - font.Height));
            }
            grBuffer.Dispose();
            captureBox.CreateGraphics().DrawImage(imageBuffer, 0, 0);
        }
Esempio n. 12
0
        public static System.IO.MemoryStream GetValidateImg(out string code, string bgImg = "/Images/vcodebg.png")
        {
            code = GetValidateCode();
            Random rnd = new Random();

            System.Drawing.Bitmap   img    = new System.Drawing.Bitmap((int)Math.Ceiling((code.Length * 17.2)), 28);
            System.Drawing.Image    bg     = System.Drawing.Bitmap.FromFile(HttpContext.Current.Server.MapPath(bgImg));
            System.Drawing.Graphics g      = System.Drawing.Graphics.FromImage(img);
            System.Drawing.Font     font   = new System.Drawing.Font("Arial", 16, (System.Drawing.FontStyle.Regular | System.Drawing.FontStyle.Italic));
            System.Drawing.Font     fontbg = new System.Drawing.Font("Arial", 16, (System.Drawing.FontStyle.Regular | System.Drawing.FontStyle.Italic));
            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, img.Width, img.Height), System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 1.2f, true);
            g.DrawImage(bg, 0, 0, new System.Drawing.Rectangle(rnd.Next(bg.Width - img.Width), rnd.Next(bg.Height - img.Height), img.Width, img.Height), System.Drawing.GraphicsUnit.Pixel);
            g.DrawString(code, fontbg, System.Drawing.Brushes.White, 0, 1);
            g.DrawString(code, font, System.Drawing.Brushes.Green, 0, 1);//字颜色

            //画图片的背景噪音线
            int x  = img.Width;
            int y1 = rnd.Next(5, img.Height);
            int y2 = rnd.Next(5, img.Height);

            g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Green, 2), 1, y1, x - 2, y2);


            g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Transparent), 0, 10, img.Width - 1, img.Height - 1);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return(ms);
        }
Esempio n. 13
0
 /// <summary>
 /// 绘制拖拽矩形,本函数根据主矩形区域计算8个拖拽矩形区域并用指定的颜色
 /// 填充和绘制边框,本函数不绘制主矩形区域
 /// </summary>
 /// <param name="myGraph">图像绘制对象</param>
 public void RefreshView(System.Drawing.Graphics myGraph)
 {
     if (myGraph != null)
     {
         if (bolBoundsBorder)
         {
             using (System.Drawing.Pen myPen =
                        new System.Drawing.Pen(System.Drawing.Color.Black))
             {
                 myPen.DashStyle = this.LineDashStyle;
                 myGraph.DrawRectangle(myPen, myBounds);
             }
         }
         using (System.Drawing.SolidBrush myBrush =
                    new System.Drawing.SolidBrush(this.DragRectBackColor))
         {
             myGraph.FillRectangles(myBrush, this.myDragRect);
         }
         using (System.Drawing.Pen myPen =
                    new System.Drawing.Pen(this.DragRectBorderColor))
         {
             myGraph.DrawRectangles(myPen, myDragRect);
         }
     }
 }// void DrawDragRect()
Esempio n. 14
0
 public override void DrawRectangle(CommonGui.Drawing.Pen pen, RectangleF rect)
 {
     using (System.Drawing.Pen pen2 = CreatePen(pen))
     {
         InternalGraphics.DrawRectangle(pen2, rect.Left, rect.Top, rect.Width, rect.Height);
     }
 }
Esempio n. 15
0
        public void CreateImage(string str_ValidateCode)
        {
            int    int_ImageWidth = str_ValidateCode.Length * 14;
            Random newRandom      = new Random();

            System.Drawing.Bitmap   theBitmap   = new System.Drawing.Bitmap(int_ImageWidth, 20);
            System.Drawing.Graphics theGraphics = System.Drawing.Graphics.FromImage(theBitmap);
            theGraphics.Clear(System.Drawing.Color.White);
            theGraphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.LightGray, 1), 0, 0, int_ImageWidth - 1, 19);
            System.Drawing.Font theFont = new System.Drawing.Font("Arial", 10);
            for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
            {
                string str_char = str_ValidateCode.Substring(int_index, 1);
                System.Drawing.Brush newBrush = new System.Drawing.SolidBrush(GetRandomColor());
                System.Drawing.Point thePos   = new System.Drawing.Point(int_index * 13 + 1 + newRandom.Next(3), 1 + newRandom.Next(3));
                theGraphics.DrawString(str_char, theFont, newBrush, thePos);
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            theBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            Response.ClearContent();
            Response.ContentType = "image/Png";
            Response.BinaryWrite(ms.ToArray());
            theGraphics.Dispose();
            theBitmap.Dispose();
            Response.End();
        }
 private void CellPaintEventHandler(object sender, object e)
 {
     try
     {
         int lRowNumber = (int)(long)e.GetType().InvokeMember("RowNumber", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public, null, e, null);
         Microsoft.SqlServer.Management.UI.Grid.GridColumn oCol = (Microsoft.SqlServer.Management.UI.Grid.GridColumn)e.GetType().InvokeMember("GridColumn", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public, null, e, null);
         int iColumnIndex = oCol.ColumnIndex;
         Microsoft.SqlServer.Management.UI.Grid.DlgGridControl grid2 = (Microsoft.SqlServer.Management.UI.Grid.DlgGridControl)sender;
         Microsoft.SqlServer.Management.UI.Grid.GridCell       cell  = grid2.GetCellInfo(lRowNumber, iColumnIndex);
         TriStatePerspectiveGridCell cell2 = cell as TriStatePerspectiveGridCell;
         if (cell2 != null && cell2.OverrideBkBrush != null)
         {
             int iSelectedRow = 0;
             int iSelectedCol = 0;
             grid2.GetSelectedCell(out iSelectedRow, out iSelectedCol);
             if (iSelectedCol == iColumnIndex && iSelectedRow == lRowNumber && cell2.OverrideBkBrush.Color != System.Drawing.Color.Red)
             {
                 return; //to avoid this selected cell looking funny when it's not highlighted but selected
             }
             System.Drawing.Graphics  g    = (System.Drawing.Graphics)e.GetType().InvokeMember("Graphics", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public, null, e, null);
             System.Drawing.Rectangle rect = (System.Drawing.Rectangle)e.GetType().InvokeMember("CellRectangle", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public, null, e, null);
             rect.X      += 1;
             rect.Y      += 2;
             rect.Width  -= 2;
             rect.Height -= 3;
             g.DrawRectangle(new System.Drawing.Pen(cell2.OverrideBkBrush.Color, (float)2), rect);
         }
     }
     catch { }
 }
Esempio n. 17
0
        public void DrawGat()
        {
            System.Drawing.Pen  pBlack = new System.Drawing.Pen(System.Drawing.Color.Black);
            System.Drawing.Pen  pRed   = new System.Drawing.Pen(System.Drawing.Color.Red);
            System.Drawing.Pen  pPink  = new System.Drawing.Pen(System.Drawing.Color.Pink);
            System.Drawing.Font font   = new System.Drawing.Font("Tahoma", 7);
            int scale = 25;

            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width * scale, Height * scale)) {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) {
                    for (int x = 0; x < Width; x++)
                    {
                        for (int y = 0; y < Height; y++)
                        {
                            int xs = x * scale;
                            int ys = y * scale;
                            if (CheckCell(x, y, ECollisionType.Walkable) == true)
                            {
                                g.DrawRectangle(pPink, xs, ys, scale, scale);
                                g.DrawString(x.ToString(), font, System.Drawing.Brushes.Black, xs + 1, ys + 1);
                                g.DrawString(y.ToString(), font, System.Drawing.Brushes.Black, xs + 1, ys + 1 + (scale / 2f));
                            }
                            else
                            {
                                g.DrawRectangle(pBlack, xs, ys, scale, scale);
                                g.DrawString(x.ToString(), font, System.Drawing.Brushes.White, xs + 1, ys + 1);
                                g.DrawString(y.ToString(), font, System.Drawing.Brushes.White, xs + 1, ys + 1 + (scale / 2f));
                            }

                            /*
                             * g.DrawLine(pRed, new System.Drawing.Point(xs, ys), new System.Drawing.Point(xs + scale, ys));
                             * g.DrawLine(pRed, new System.Drawing.Point(xs + scale, ys), new System.Drawing.Point(xs + scale, ys + scale));
                             * g.DrawLine(pRed, new System.Drawing.Point(xs, ys), new System.Drawing.Point(xs, ys + scale));
                             * g.DrawLine(pRed, new System.Drawing.Point(xs, ys + scale), new System.Drawing.Point(xs + scale, ys + scale));
                             */
                        }
                    }

                    string filename = "mapdebug_" + Name.ToLower() + ".png";
                    if (System.IO.File.Exists(filename) == true)
                    {
                        System.IO.File.Delete(filename);
                    }
                    bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }
Esempio n. 18
0
 public void DrawCurve(System.Drawing.Graphics Graphic)
 {
     for (int i = 0; i < CurvePoints.Count; i++)
     {
         Graphic.DrawRectangle(MyPens[ColourIdx], (float)CurvePoints[i].X, (float)CurvePoints[i].Y, 1, 1);
     }
     //Graphic.DrawBezier(MyPens[ColourIdx], (float)Points[0].X, (float)Points[0].Y, (float)Points[1].X, (float)Points[1].Y, (float)Points[2].X, (float)Points[2].Y, (float)Points[3].X, (float)Points[3].Y);
 }
Esempio n. 19
0
 public static bool DrawRectangle(
     System.Drawing.Graphics g,
     System.Drawing.Pen BorderPen,
     System.Drawing.Brush FillBrush,
     System.Drawing.Rectangle Bounds,
     System.Drawing.Rectangle ClipRectangle,
     bool ForceDrawBorder)
 {
     System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty;
     if (ClipRectangle.IsEmpty)
     {
         rect = Bounds;
     }
     else
     {
         rect = System.Drawing.Rectangle.Intersect(Bounds, ClipRectangle);
     }
     if (rect.IsEmpty)
     {
         return(false);
     }
     if (FillBrush != null)
     {
         g.FillRectangle(FillBrush, rect);
     }
     if (BorderPen != null)
     {
         rect = new System.Drawing.Rectangle(
             Bounds.Left,
             Bounds.Top,
             Bounds.Width - (int)Math.Ceiling(BorderPen.Width / 2.0),
             Bounds.Height - (int)Math.Ceiling(BorderPen.Width / 2.0));
         if (ForceDrawBorder || ClipRectangle.IsEmpty)
         {
             g.DrawRectangle(BorderPen, rect);
         }
         else
         {
             if (rect.IntersectsWith(ClipRectangle))
             {
                 g.DrawRectangle(BorderPen, rect);
             }
         }
     }
     return(true);
 }
Esempio n. 20
0
        private void On_TakeImageButtonClick(object sender, EventArgs e)
        {
            if (webCam != null)
            {
                if (stillImageBox.Image != null)
                {
                    stillImageBox.Image.Dispose();
                }
                if (originalPicture != null)
                {
                    originalPicture.Dispose();
                }
                try
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    // Release any previous buffer
                    if (ip != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(ip);
                        ip = IntPtr.Zero;
                    }
                    // capture image
                    ip = webCam.Click();
                    originalPicture = new System.Drawing.Bitmap(webCam.Width, webCam.Height, webCam.Stride, PixelFormat.Format24bppRgb, ip);
                    originalPicture.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

                    System.Drawing.Bitmap result = new System.Drawing.Bitmap(200, 150);
                    using (System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(result))
                    {
                        graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        graph.DrawImage(originalPicture, 0, 0, 200, 150);
                        System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Purple, 1);
                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                graph.DrawRectangle(pen, 25 + 25 - 10 + 50 * j, 25 - 10 + 50 * i, 20, 20);
                            }
                        }
                        pen.Dispose();
                    }
                    stillImageBox.Image = result;
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
                catch
                {
                    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(VIDEOWIDTH, VIDEOHEIGHT);
                    using (System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        System.Drawing.Rectangle size = new System.Drawing.Rectangle(0, 0, VIDEOWIDTH, VIDEOHEIGHT);
                        graph.FillRectangle(System.Drawing.Brushes.White, size);
                    }
                    stillImageBox.Image = bitmap;
                    webCam.Dispose();
                    webCam = null;
                }
            }
        }
Esempio n. 21
0
        private void PrintBorder(System.Drawing.Graphics graphics, Point leftTopPosition, Size itemSize)
        {
            _borderPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
            int width = (int)_borderPen.Width;

            if (itemSize.Width >= width && itemSize.Height >= width)
            {
                graphics.DrawRectangle(_borderPen, leftTopPosition.X, leftTopPosition.Y, itemSize.Width, itemSize.Height);
            }
            else
            {
                float oldWidth = _borderPen.Width;

                _borderPen.Width = Math.Min(itemSize.Width, itemSize.Height);
                graphics.DrawRectangle(_borderPen, leftTopPosition.X, leftTopPosition.Y, itemSize.Width, itemSize.Height);
                _borderPen.Width = oldWidth;
            }
        }
Esempio n. 22
0
        private void DrawGrid(System.Drawing.Graphics g)
        {
            g.DrawRectangle(CurrentPen as System.Drawing.Pen, new System.Drawing.Rectangle(0, 0, (int)szScreen.X, (int)szScreen.Y));

            System.Drawing.Pen p1 = new System.Drawing.Pen(System.Drawing.Color.White, 1);
            System.Drawing.Pen p2 = new System.Drawing.Pen(System.Drawing.Color.White, 2);

            double gridSpacing = 10;

            double x = -(ptViewport.X);

            if (x % 10 != 0)
            {
                x -= (ptViewport.X % 10);
            }
            for (; x <= szViewport.X - ptViewport.X; x += gridSpacing)
            {
                g.DrawLine(x != 0 ? p1 : p2,
                           viewportToScreen(new Point(x, -ptViewport.Y)),
                           viewportToScreen(new Point(x, szScreen.Y)));
            }
            for (x = -(ptViewport.X); x <= szViewport.X - ptViewport.X; x += 1)
            {
                double hashSize = 1;
                if (x % 5 == 0)
                {
                    hashSize = 2;
                }
                g.DrawLine(x != 0 ? p1 : p2,
                           viewportToScreen(new Point(x, -hashSize)),
                           viewportToScreen(new Point(x, hashSize)));
            }

            double y = -(ptViewport.Y);

            if (y % 10 != 0)
            {
                y -= (ptViewport.Y % 10);
            }
            for (; y <= szViewport.Y - ptViewport.Y; y += gridSpacing)
            {
                g.DrawLine(y != 0 ? p1 : p2,
                           viewportToScreen(new Point(-ptViewport.X, y)),
                           viewportToScreen(new Point(szScreen.X, y)));
            }
            for (y = -(ptViewport.Y); y <= szViewport.Y - ptViewport.Y; y += 1)
            {
                double hashSize = 1;
                if (y % 5 == 0)
                {
                    hashSize = 2;
                }
                g.DrawLine(y != 0 ? p1 : p2,
                           viewportToScreen(new Point(-hashSize, y)),
                           viewportToScreen(new Point(hashSize, y)));
            }
        }
Esempio n. 23
0
        public void Draw(System.Drawing.Bitmap bitmap, List <System.Drawing.Point> points)
        {
            System.Drawing.Point startPoint = points[0], endPoint = points[1];

            System.Drawing.Pen      pen = new System.Drawing.Pen(System.Drawing.Brushes.Blue, 3);
            System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(bitmap);
            g.DrawRectangle(pen, startPoint.X, startPoint.Y, endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);

            pen.Dispose(); g.Dispose();
        }
Esempio n. 24
0
 /// <summary>
 /// 给图片打上框和文字
 /// </summary>
 /// <param name="bitmap"></param>
 /// <param name="rectangle"></param>
 /// <param name="text"></param>
 public static System.Drawing.Bitmap RectBitmap(this System.Drawing.Bitmap bitmap, System.Drawing.Rectangle rectangle, string text = "")
 {
     ///获取绘图句柄
     using (System.Drawing.Graphics graphisc = System.Drawing.Graphics.FromImage(bitmap))
     {
         graphisc.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Red), rectangle);
         graphisc.DrawString(text, new System.Drawing.Font("宋体", 15), System.Drawing.Brushes.Red, new System.Drawing.PointF(rectangle.X, rectangle.Y - 15));
     }
     return(bitmap);
 }
Esempio n. 25
0
 private void mainLayout_Enter(object sender, EventArgs e)
 {
     System.Drawing.Bitmap   img = new System.Drawing.Bitmap(2, 12);
     System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(img);
     g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.FromArgb(0, 255, 255)), 0, 0, 3, 12);
     this.mainLayout.Focus();
     DestroyCaret();
     CreateCaret(this.mainLayout.Handle.ToInt32(), img.GetHbitmap().ToInt32(), img.Width, img.Height);
     ShowCaret(this.mainLayout.Handle.ToInt32());
 }
Esempio n. 26
0
        public override void Draw(System.Drawing.Graphics drawArea)
        {
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            drawArea.FillRectangle(myBrush, posX, posY, sides[0], sides[0]);
            myBrush.Dispose();

            System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.LightGreen);
            myPen.Width = 5;
            drawArea.DrawRectangle(myPen, posX, posY, sides[0], sides[0]);
            myPen.Dispose();
        }
Esempio n. 27
0
 public void dbug_HighlightMeNow(Rectangle rect)
 {
     using (System.Drawing.Pen mpen = new System.Drawing.Pen(System.Drawing.Brushes.White, 2))
         using (System.Drawing.Graphics g = this.dbugCreateGraphics())
         {
             System.Drawing.Rectangle r = rect.ToRect();
             g.DrawRectangle(mpen, r);
             g.DrawLine(mpen, new System.Drawing.Point(r.X, r.Y), new System.Drawing.Point(r.Right, r.Bottom));
             g.DrawLine(mpen, new System.Drawing.Point(r.X, r.Bottom), new System.Drawing.Point(r.Right, r.Y));
         }
 }
Esempio n. 28
0
 protected override void WndProc(ref Message m)
 {
     base.WndProc(ref m);
     if (m.Msg == WM_NCPAINT)
     {
         var dc = GetWindowDC(Handle);
         using (System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(dc))
         {
             g.DrawRectangle(System.Drawing.Pens.DarkGray, 0, 0, Width - 1, Height - 1);
         }
     }
 }
        public virtual void Draw(System.Drawing.Graphics g)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }

            if (_areaOriginDefined && _areaDefined)
            {
                g.DrawRectangle(_borderPen, _objectHost.HostViewer.WorkspaceToControl(this.Area, Aurigma.GraphicsMill.Unit.Point));
            }
        }
Esempio n. 30
0
        public void DrawClippingWindow(IClippingWindow window, System.Drawing.Graphics g)
        {
            RectangularClippingWindow rectWindow = window as RectangularClippingWindow;

            if (rectWindow != null)
            {
                g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Blue, 1),
                                rectWindow.TopLeft.X, rectWindow.TopLeft.Y,
                                rectWindow.TopRight.X - rectWindow.TopLeft.X,
                                rectWindow.BottomLeft.Y - rectWindow.TopLeft.Y);
            }
        }
        public override void Draw(Graphics g)
        {
            base.Draw(g);
            if (Annotation.Polygon.Length == 0) return;

            var pt = this.Annotation.Polygon
                         .Select(x => Element.ToPictureBoxCoordinate(x.ToPt()).ToPt())
                         .Select(x => x.Round())
                         .First();

            //pt = Element.ToPictureBoxCoordinate(new Point(475, 306).ToPt()).ToPt().Round();

            g.DrawRectangle(Pen, new System.Drawing.Rectangle(pt.X - RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, RECT_SIZE, RECT_SIZE));
            g.DrawLine(Pen, pt.X - RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, pt.X + RECT_SIZE / 2, pt.Y + RECT_SIZE / 2); // \
            g.DrawLine(Pen, pt.X + RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, pt.X - RECT_SIZE / 2, pt.Y + RECT_SIZE / 2); // /
        }
Esempio n. 32
0
        public void ShowBorders(object sender,MouseEventArgs e)
        {
            Panel tPanel = (Panel)sender;

            if (objGraphics != null) return;
            else objGraphics = null;
            objGraphics = tPanel.CreateGraphics();
            objGraphics.Clear(System.Drawing.SystemColors.Control);

            foreach(Control pp in tPanel.Controls)
            {
                if (pp is PictureBox)
                {
                    //画边界
                    objGraphics.DrawRectangle(System.Drawing.Pens.BlueViolet, pp.Left - 1, pp.Top - 1, pp.Width + 1, pp.Height + 1);
                }
                else objGraphics = null;
            }
        }