public static List <Rectangle> GetTextLineRects(Bitmap chatImage, int threshold = 5)
        {
            using (var finder = new TextLinesFinder(chatImage, threshold))
            {
                var lines = finder.GetTextLines();
                if (lines.Count > 0)
                {
                    lines.RemoveAt(0);
                }

                return(lines);
            }
        }
Exemplo n.º 2
0
        public void UpdateFrame(Bitmap chatImage)
        {
            var currentFrameLines = TextLinesFinder.GetTextLineRects(chatImage);

            if (this.previousFrame != null)
            {
                if (Utils.AreSimilar(this.previousFrame, chatImage))
                {
                    this.NewLines = new ChatLineInfo[0];
                }
                else
                {
                    var previousLastLinePositionInNewFrame = this.previousFrameLastLine != Rectangle.Empty ? Utils.FindSimilar(this.previousFrame, this.previousFrameLastLine, chatImage) : -1;
                    if (previousLastLinePositionInNewFrame == -1)
                    {
                        this.NewLines = currentFrameLines.Select(r => new ChatLineInfo(chatImage, r)).ToArray();
                    }
                    else
                    {
                        var previousFrameBottom = previousLastLinePositionInNewFrame + this.previousFrameLastLine.Height;
                        this.NewLines = currentFrameLines.Where(l => l.Y > previousFrameBottom).Select(r => new ChatLineInfo(chatImage, r)).ToArray();
                    }
                }
            }
            else
            {
                this.NewLines = this.onlyNewMessages ? new ChatLineInfo[0] : currentFrameLines.Select(r => new ChatLineInfo(chatImage, r)).ToArray();
            }

            if (this.previousFrame != null)
            {
                this.previousFrame.Dispose();
            }

            this.previousFrame = chatImage;
            if (currentFrameLines.Count > 0)
            {
                this.previousFrameLastLine = currentFrameLines[currentFrameLines.Count - 1];
            }
            else
            {
                this.previousFrameLastLine = Rectangle.Empty;
            }
        }