示例#1
0
        private void pic_grid_Paint(object sender, PaintEventArgs e)
        {
            if (!_gridInit)
            {
                LinkPoint();
                return;
            }

            DrawF draw = new DrawF(79.0f, 5.0f, 5.0f);

            for (int col = 0; col < 5; col++)
            {
                for (int row = 0; row < 5; row++)
                {
                    PointF2D point = _points[col, row];
                    if (row < 4)
                    {
                        PointF2D rightPoint = _points[col, row + 1];
                        draw.drawLine(e.Graphics, point.X, point.Y, rightPoint.X, rightPoint.Y);
                    }

                    if (col < 4)
                    {
                        PointF2D bottomPoint = _points[col + 1, row];
                        draw.drawLine(e.Graphics, point.X, point.Y, bottomPoint.X, bottomPoint.Y);
                    }
                }
            }
            _gridInit = false;
        }
示例#2
0
        private void LinkPoint()
        {
            DrawF draw = new DrawF(79.0f, 5.0f, 5.0f);
            BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            BufferedGraphics        bufferGraphics = currentContext.Allocate(pic_grid.CreateGraphics(), pic_grid.DisplayRectangle);

            _gridImage = new Bitmap(_fileImage.Width, _fileImage.Height);
            Graphics graphics    = bufferGraphics.Graphics;
            Graphics graphicsBMP = Graphics.FromImage(_gridImage);

            graphics.Clear(pic_grid.BackColor);
            graphicsBMP.FillRectangle(Brushes.White, 0, 0, _fileImage.Width, _fileImage.Height);
            for (int col = 0; col < 5; col++)
            {
                for (int row = 0; row < 5; row++)
                {
                    PointF2D point = _points[col, row];
                    float    x1    = point.X - 10 == _fileImage.Width ? point.X - 11 : point.X - 10;
                    float    y1    = point.Y - 10 == _fileImage.Height ? point.Y - 11 : point.Y - 10;
                    if (row < 4)
                    {
                        PointF2D rightPoint = _points[col, row + 1];
                        float    x2         = rightPoint.X - 10 == _fileImage.Width ? rightPoint.X - 11 : rightPoint.X - 10;
                        float    y2         = rightPoint.Y - 10 == _fileImage.Height ? rightPoint.Y - 11 : rightPoint.Y - 10;
                        draw.drawLine(graphics, point.X, point.Y, rightPoint.X, rightPoint.Y);
                        draw.drawLine(graphicsBMP, x1, y1, x2, y2, 3);
                    }

                    if (col < 4)
                    {
                        PointF2D bottomPoint = _points[col + 1, row];
                        float    x2          = bottomPoint.X - 10 == _fileImage.Width ? bottomPoint.X - 11 : bottomPoint.X - 10;
                        float    y2          = bottomPoint.Y - 10 == _fileImage.Height ? bottomPoint.Y - 11 : bottomPoint.Y - 10;
                        draw.drawLine(graphics, point.X, point.Y, bottomPoint.X, bottomPoint.Y);
                        draw.drawLine(graphicsBMP, x1, y1, x2, y2, 3);
                    }
                }
            }
            if (ch_timely.Checked)
            {
                pic_result.Image = _lib.PerspectiveTransform8bit(_grayImage, _points, _transType);
            }
            //int[,] graph = new int[pic_grid.Height, pic_grid.Width];
            //int mark = 1;
            //List<int> links = new List<int>();
            //links.Add(0);
            //for (int row = 1; row < bmpPic.Height - 1; row++)
            //{
            //    for (int col = 1; col < bmpPic.Width - 1; col++)
            //    {
            //        List<int> link = new List<int>();

            //        if (bmpPic.GetPixel(col, row).R != 255)
            //        {
            //            continue;
            //        }

            //        if (graph[row - 1, col - 1] != 0)
            //        {
            //            link.Add(graph[row - 1, col - 1]);
            //        }

            //        if (graph[row - 1, col] != 0)
            //        {
            //            link.Add(graph[row - 1, col]);
            //        }

            //        if (graph[row - 1, col + 1] != 0)
            //        {
            //            link.Add(graph[row - 1, col + 1]);
            //        }

            //        if (graph[row, col - 1] != 0)
            //        {
            //            link.Add(graph[row, col - 1]);
            //        }

            //        if (link.Count == 0)
            //        {
            //            links.Add(mark);
            //            graph[row, col] = mark++;
            //        }
            //        else
            //        {
            //            link.Sort();
            //            int minLink = links[link[0]];
            //            for (int index = 0; index < link.Count; index++)
            //            {
            //                if (minLink < links[link[index]])
            //                {
            //                    links[link[index]] = minLink;
            //                }
            //                else if (minLink > links[link[index]])
            //                {
            //                    links[link[0]] = links[link[index]];
            //                }
            //            }
            //            graph[row, col] = minLink;
            //        }
            //    }
            //}

            //for (int index = 1; index < links.Count(); index++)
            //{
            //    int saveValue = links[index];
            //    int saveValueIndex = index;
            //    while (saveValue != saveValueIndex)
            //    {
            //        saveValue = links[links[saveValueIndex]];
            //        saveValueIndex = links[saveValueIndex];
            //    }
            //    links[index] = saveValue;
            //}
            //HashSet<int> companyTeams = new HashSet<int>();
            //for (int row = 1; row < bmpPic.Height - 1; row++)
            //{
            //    for (int col = 1; col < bmpPic.Width - 1; col++)
            //    {

            //        if (bmpPic.GetPixel(col, row).R != 255)
            //        {
            //            continue;
            //        }
            //        graph[row, col] = links[graph[row, col]];
            //        companyTeams.Add(graph[row, col]);
            //    }
            //}

            //Color[] colors = new Color[companyTeams.Count + 1];
            //Dictionary<int, int> norml = new Dictionary<int, int>();
            //for (int index = 0; index < companyTeams.Count + 1; index++)
            //{
            //    colors[index] = GetColor(index);
            //}
            //norml[0] = 0;
            //int offset = 1;
            //foreach (int data in companyTeams)
            //{
            //    norml[data] = offset;
            //    offset++;
            //}

            //for (int row = 0; row < pic_grid.Height; row++)
            //{
            //    for (int col = 0; col < pic_grid.Width; col++)
            //    {
            //        //bmpPic.SetPixel(col, row, colors[norml[graph[row, col]]]);
            //        if (bmpPic.GetPixel(col, row).R != 0)
            //        {
            //            continue;
            //        }
            //    }
            //}
            //_gridImage.Save(@"D:/test.bmp");
            bufferGraphics.Render(pic_grid.CreateGraphics());
            bufferGraphics.Dispose();
        }