コード例 #1
0
        public Bitmap DisplayOCR(Bitmap shot, HexGrid grid)
        {
            shot = new Bitmap(shot);

            using (Graphics g = Graphics.FromImage(shot))
            {
                g.FillRectangle(new SolidBrush(Color.White), 0, 0, shot.Width, shot.Height);

                Font         fnt       = new Font("Arial", 12, FontStyle.Bold);
                Font         fnt_big   = new Font("Arial", 22, FontStyle.Bold);
                Brush        fntBush1  = new SolidBrush(Color.Black);
                Brush        fntBush2  = new SolidBrush(Color.FromArgb(32, Color.Black));
                Brush        fntBush3  = new SolidBrush(Color.Red);
                Pen          bluepen   = new Pen(Color.FromArgb(0, 164, 235));
                Brush        bluebrush = new SolidBrush(Color.FromArgb(128, 0, 164, 235));
                StringFormat fmt       = new StringFormat
                {
                    LineAlignment = StringAlignment.Center,
                    Alignment     = StringAlignment.Center
                };

                foreach (var hex in grid)
                {
                    var points = Enumerable.Range(0, 7).Select(p => hex.Value.GetEdge(p)).Select(p => new Point((int)p.X, (int)p.Y)).ToArray();

                    if (hex.Value.Type == HexagonType.NOCELL)
                    {
                        g.FillPolygon(new SolidBrush(Color.Gainsboro), points);
                    }
                    else
                    {
                        g.FillPolygon(new SolidBrush(Color.SlateGray), points);
                    }

                    if (hex.Value.Hint.Type != CellHintType.NONE)
                    {
                        if (hex.Value.Hint.Area == CellHintArea.CIRCLE)
                        {
                            Vec2d  center    = hex.Value.Image.OCRCenter;
                            double hexheight = hex.Value.Image.OCRHeight * 0.8;

                            g.FillEllipse(bluebrush, (int)(center.X - hexheight), (int)(center.Y - hexheight), (int)(2 * hexheight), (int)(2 * hexheight));
                            g.DrawEllipse(bluepen, (int)(center.X - hexheight), (int)(center.Y - hexheight), (int)(2 * hexheight), (int)(2 * hexheight));
                        }
                        else if (hex.Value.Hint.Area == CellHintArea.COLUMN_LEFT)
                        {
                            Vec2d p1 = hex.Value.Image.GetEdge(0);
                            Vec2d p2 = hex.Value.Image.GetEdge(1);
                            Vec2d pm = p1 - p2;
                            pm.Rotate(MathExt.ToRadians(-90));
                            pm.SetLength(hex.Value.Image.OCRHeight / 4);

                            Point[] polypoints = new[] { p1, p2, p2 + pm, p1 + pm, p1 }.Select(p => new Point((int)p.X, (int)p.Y)).ToArray();

                            g.FillPolygon(bluebrush, polypoints);
                            g.DrawPolygon(bluepen, polypoints);
                        }
                        else if (hex.Value.Hint.Area == CellHintArea.COLUMN_DOWN)
                        {
                            Vec2d p1 = hex.Value.Image.GetEdge(5);
                            Vec2d p2 = hex.Value.Image.GetEdge(0);
                            Vec2d pm = p1 - p2;
                            pm.Rotate(MathExt.ToRadians(-90));
                            pm.SetLength(hex.Value.Image.OCRHeight / 4);

                            Point[] polypoints = new[] { p1, p2, p2 + pm, p1 + pm, p1 }.Select(p => new Point((int)p.X, (int)p.Y)).ToArray();

                            g.FillPolygon(bluebrush, polypoints);
                            g.DrawPolygon(bluepen, polypoints);
                        }
                        else if (hex.Value.Hint.Area == CellHintArea.COLUMN_RIGHT)
                        {
                            Vec2d p1 = hex.Value.Image.GetEdge(4);
                            Vec2d p2 = hex.Value.Image.GetEdge(5);
                            Vec2d pm = p1 - p2;
                            pm.Rotate(MathExt.ToRadians(-90));
                            pm.SetLength(hex.Value.Image.OCRHeight / 4);

                            Point[] polypoints = new[] { p1, p2, p2 + pm, p1 + pm, p1 }.Select(p => new Point((int)p.X, (int)p.Y)).ToArray();

                            g.FillPolygon(bluebrush, polypoints);
                            g.DrawPolygon(bluepen, polypoints);
                        }

                        g.DrawString(hex.Value.Hint.ToString(), fnt, fntBush1, hex.Value.Image.BoundingBox, fmt);
                    }
                    else
                    {
                        if (hex.Value.Type == HexagonType.NOCELL || hex.Value.Type == HexagonType.HIDDEN)
                        {
                            g.DrawString(hex.Value.Hint.ToString(), fnt, fntBush2, hex.Value.Image.BoundingBox, fmt);
                        }
                        else if (hex.Value.Type == HexagonType.UNKNOWN)
                        {
                            g.DrawString(hex.Value.Hint.ToString(), fnt, fntBush3, hex.Value.Image.BoundingBox, fmt);
                        }
                        else
                        {
                            g.DrawString(hex.Value.Hint.ToString(), fnt, fntBush1, hex.Value.Image.BoundingBox, fmt);
                        }
                    }
                }

                g.FillRectangle(new SolidBrush(Color.SlateGray), grid.CounterArea.BoundingBox);
                g.DrawString(grid.CounterArea.Value.Value.ToString(), fnt_big, fntBush1, grid.CounterArea.BoundingBox, fmt);
            }

            return(shot);
        }
コード例 #2
0
        public Bitmap DisplayOCRDistance(Bitmap shot, HexGrid grid)
        {
            shot = new Bitmap(shot);

            using (Graphics g = Graphics.FromImage(shot))
            {
                g.FillRectangle(new SolidBrush(Color.White), 0, 0, shot.Width, shot.Height);

                Font         fnt_small = new Font("Arial", 7, FontStyle.Italic);
                Font         fnt       = new Font("Arial", 12, FontStyle.Bold);
                Font         fnt_big   = new Font("Arial", 22, FontStyle.Bold);
                Brush        fntBush1  = new SolidBrush(Color.Black);
                StringFormat fmt       = new StringFormat
                {
                    LineAlignment = StringAlignment.Center,
                    Alignment     = StringAlignment.Center
                };
                StringFormat fmt_down = new StringFormat
                {
                    LineAlignment = StringAlignment.Far,
                    Alignment     = StringAlignment.Center
                };

                foreach (var hex in grid)
                {
                    var points = Enumerable.Range(0, 7).Select(p => hex.Value.GetEdge(p)).Select(p => new Point((int)p.X, (int)p.Y)).ToArray();


                    if (hex.Value.Hint.Type == CellHintType.NONE && hex.Value.Hint.OCRDistance > 0 && hex.Value.Hint.AltDisplayValue != null)
                    {
                        double perc = Math.Min(1.0, hex.Value.Hint.OCRDistance / 35.0);
                        int    col  = (int)(perc * 255);

                        g.FillPolygon(new SolidBrush(Color.FromArgb(col, 255 - col, 0)), points);

                        g.DrawString(hex.Value.Hint.AltDisplayValue, fnt, fntBush1, hex.Value.Image.BoundingBox, fmt);
                        g.DrawString("" + (int)hex.Value.Hint.OCRDistance, fnt_small, fntBush1, hex.Value.Image.BoundingBox, fmt_down);
                    }
                    else if (hex.Value.Hint.Type != CellHintType.NONE)
                    {
                        double perc = Math.Min(1.0, hex.Value.Hint.OCRDistance / 35.0);
                        int    col  = (int)(perc * 255);

                        g.FillPolygon(new SolidBrush(Color.FromArgb(col, 255 - col, 0)), points);

                        g.DrawString(hex.Value.Hint.ToString(), fnt, fntBush1, hex.Value.Image.BoundingBox, fmt);
                        g.DrawString("" + (int)hex.Value.Hint.OCRDistance, fnt_small, fntBush1, hex.Value.Image.BoundingBox, fmt_down);
                    }
                    else
                    {
                        g.FillPolygon(new SolidBrush(Color.FloralWhite), points);
                    }
                }

                {
                    double perc = Math.Min(1.0, grid.CounterArea.Value.OCRDistance / 50.0);
                    int    col  = (int)(perc * 255);

                    g.FillRectangle(new SolidBrush(Color.FromArgb(col, 255 - col, 0)), grid.CounterArea.BoundingBox);
                    g.DrawString(grid.CounterArea.Value.Value.ToString(), fnt_big, fntBush1, grid.CounterArea.BoundingBox, fmt);
                }
            }

            return(shot);
        }