Exemplo n.º 1
0
        public Image EraseLines(Bitmap targetImg, Color color, List <Rectangle> Regions)
        {
            if (Regions.Count == 0)
            {
                return(EraseLines(targetImg, color));
            }
            Counter counter = new Counter(this.outputHanler);

            counter.Start("EraseLines");
            //水平線
            Bitmap     newImg    = targetImg.Clone(new Rectangle(0, 0, targetImg.Width, targetImg.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            LockBitmap imgLocker = new LockBitmap(newImg);

            imgLocker.LockBits();
            //TestGetPixle(imgLocker);
            List <MergeLineInfo> Hlines = ScanLines(imgLocker, LineDirction.Horizontal);
            //縦線
            List <MergeLineInfo> Vlines = ScanLines(imgLocker, LineDirction.Vertical);

            imgLocker.UnlockBits();
            using (Graphics g = Graphics.FromImage(newImg))
            {
                EraseAllLines(g, Hlines, Vlines, Regions);
            }
            counter.End();
            return(newImg);
        }
Exemplo n.º 2
0
 public void Erase(LockBitmap img, Color color)
 {
     if (this.IsLine)
     {
         foreach (LineInfo line in this.Lines)
         {
             line.Erase(img, color);
         }
     }
 }
Exemplo n.º 3
0
        private int SearchBlackStart(LockBitmap img, int x, int y, int maxLength, LineDirction lineType)
        {
            Color color = lineType == LineDirction.Horizontal ? img.GetPixel(x, y) : img.GetPixel(y, x);

            while (color.ToArgb() != Color.Black.ToArgb() && x < maxLength)
            {
                x++;
                color = lineType == LineDirction.Horizontal ? img.GetPixel(x, y) : img.GetPixel(y, x);
            }
            return(x);
        }
Exemplo n.º 4
0
        private void EraseAllLines(Color color, LockBitmap imgLocker, List <MergeLineInfo> Hlines, List <MergeLineInfo> Vlines)
        {
            Counter counter = new Counter(this.outputHanler);

            counter.Start("EraseHorizontalLines");
            //水平線クリア
            Hlines.ForEach(l => l.Erase(imgLocker, color));
            counter.End();
            //縦線クリア
            counter.Start("EraseVerticalLines");
            Vlines.ForEach(l => l.Erase(imgLocker, color));
            counter.End();
        }
Exemplo n.º 5
0
 public void Erase(LockBitmap img, Color color)
 {
     for (int x = Start; x <= End; x++)
     {
         if (LineType == LineDirction.Horizontal)
         {
             img.SetPixel(x, this.Pos, color);
         }
         else
         {
             img.SetPixel(this.Pos, x, color);
         }
     }
 }
Exemplo n.º 6
0
        private void TestGetPixle(LockBitmap img)
        {
            Counter counter = new Counter(outputHanler);

            counter.Start("TestGetPixle");
            int maxStep   = img.Height;
            int maxLength = img.Width;

            for (int y = 0; y < maxStep; y++)
            {
                for (int x = 0; x < maxLength; x++)
                {
                    Color color = img.GetPixel(x, y);
                }
            }
            counter.End();
        }
Exemplo n.º 7
0
        public Image EraseLines(Bitmap targetImg, Color color)
        {
            Counter counter = new Counter(this.outputHanler);

            counter.Start("EraseLines");
            //水平線
            Bitmap     newImg    = targetImg.Clone(new Rectangle(0, 0, targetImg.Width, targetImg.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            LockBitmap imgLocker = new LockBitmap(newImg);

            imgLocker.LockBits();
            //TestGetPixle(imgLocker);
            List <MergeLineInfo> Hlines = ScanLines(imgLocker, LineDirction.Horizontal);
            //縦線
            List <MergeLineInfo> Vlines = ScanLines(imgLocker, LineDirction.Vertical);

            EraseAllLines(color, imgLocker, Hlines, Vlines);
            imgLocker.UnlockBits();
            counter.End();
            return(newImg);
        }
Exemplo n.º 8
0
        public Image DrawLineRects(Bitmap orgImg, Color color)
        {
            //水平線
            Bitmap     newImg    = orgImg.Clone(new Rectangle(0, 0, orgImg.Width, orgImg.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            LockBitmap imgLocker = new LockBitmap(newImg);

            imgLocker.LockBits();
            List <MergeLineInfo> Hlines = ScanLines(imgLocker, LineDirction.Horizontal);
            //縦線
            List <MergeLineInfo> Vlines = ScanLines(imgLocker, LineDirction.Vertical);

            imgLocker.UnlockBits();

            Bitmap drawImg = new Bitmap(newImg);

            //水平線描画
            Hlines.ForEach(l => l.DrawRect(drawImg));
            //縦線描画
            Vlines.ForEach(l => l.DrawRect(drawImg));
            return(drawImg);
        }
Exemplo n.º 9
0
        private List <MergeLineInfo> ScanLines(LockBitmap img, LineDirction lineType)
        {
            Counter counter = new Counter(outputHanler);

            counter.Start("ScanLines -" + lineType.ToString());
            LineInfo        line      = null;
            List <LineInfo> lines     = new List <LineInfo>();
            int             maxStep   = lineType == LineDirction.Horizontal ? img.Height : img.Width;
            int             maxLength = lineType == LineDirction.Horizontal ? img.Width : img.Height;
            int             ystep     = 1;
            int             xstep     = 1;
            int             bigStep   = Env.HighSpeedStep;

            for (int y = 0; y < maxStep; y += ystep)
            {
                List <LineInfo> currentLines = new List <LineInfo>();
                line = new LineInfo(y, lineType);
                for (int x = 0; x < maxLength; x += xstep)
                {
                    Color color = lineType == LineDirction.Horizontal ? img.GetPixel(x, y) : img.GetPixel(y, x);
                    if (color.ToArgb() != Color.Black.ToArgb())
                    {
                        if (line.Start > -1)
                        {
                            currentLines.Add(line);
                            line = new LineInfo(y, lineType);
                        }
                        xstep = bigStep;
                    }
                    else
                    {
                        if (xstep == bigStep && x > bigStep - 1)
                        {
                            x = SearchBlackStart(img, x - bigStep + 1, y, maxLength, lineType);
                        }
                        xstep = 1;
                        if (line.Start == -1)
                        {
                            line.Start = x;
                            line.End   = x;
                        }
                        else
                        {
                            line.End = x;
                        }
                    }
                }
                if (line.Start != -1)
                {
                    currentLines.Add(line);
                }
                if (currentLines.Count > 0)
                {
                    List <LineInfo> dotLines = MergeDotLine(currentLines, Env.MaxDotSpace);
                    foreach (LineInfo dotLine in dotLines)
                    {
                        if (dotLine.isLine())
                        {
                            lines.Add(dotLine);
                        }
                    }
                }
                currentLines = null;
            }
            counter.End();
            return(GetMergeLines(lines));
        }