Exemplo n.º 1
0
        /// <summary>
        /// Find the target location of the image
        /// </summary>
        /// <param name="previousImage"></param>
        /// <returns>StitchInfo for fluent usage</returns>
        public StitchInfo FindTargetLocation(StitchInfo previousImage)
        {
            int currentImageHeight = _sourceRect.Height;

            // Find location in the other image
            for (int location = 0; location < previousImage.SourceRect.Height; location++)
            {
                // Do not try to match until the size makes sense
                if (_sourceRect.Height - location > currentImageHeight)
                {
                    continue;
                }

                bool isMatch = true;
                int  y       = 0;
                while (location + y < previousImage.SourceRect.Height && _sourceRect.Top + y < previousImage._sourceRect.Bottom)
                {
                    if (previousImage._hashes[previousImage._sourceRect.Top + location + y] != _hashes[_sourceRect.Top + y])
                    {
                        isMatch = false;
                        break;
                    }
                    y++;
                }

                if (!isMatch)
                {
                    continue;
                }
                _sourceRect = new NativeRect(_sourceRect.X, _sourceRect.Y + y, _sourceRect.Width, _sourceRect.Height - y);
                break;
            }
            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a bitmap to be stitched
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <returns>BitmapStitcher for fluent calling</returns>
        public BitmapStitcher AddBitmap(Bitmap bitmap)
        {
            if (!_resultPixelFormat.HasValue)
            {
                _resultPixelFormat = bitmap.PixelFormat;
            }
            var stitchInfo = new StitchInfo(bitmap);

            _stitchInfos.Add(stitchInfo);
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Scans the header, and changes the SourceRect if something is found
        /// </summary>
        /// <param name="primaryImage">StitchInfo for the first image</param>
        public StitchInfo RemoveHeader(StitchInfo primaryImage)
        {
            int headerLines = 0;

            var primaryImageHashes = primaryImage._hashes;

            // Find header
            while (headerLines < primaryImageHashes.Count && primaryImageHashes[headerLines] == _hashes[headerLines])
            {
                headerLines++;
            }
            // Not interested in 1 line
            if (headerLines > 1)
            {
                // Remove the lines, by moving the top down (and reducing the height)
                _sourceRect = new NativeRect(_sourceRect.X, headerLines, _sourceRect.Width, _sourceRect.Height - headerLines);
            }
            return(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Scans the footer, and changes the SourceRect if something is found
        /// </summary>
        /// <param name="primaryImage">StitchInfo for the first image</param>
        public StitchInfo RemoveFooter(StitchInfo primaryImage)
        {
            var primaryHashes = primaryImage._hashes;

            int footerLines = -1;
            int primaryLocation, footerLocation;

            // Find footer
            do
            {
                footerLines++;
                primaryLocation = primaryImage.SourceRect.Bottom - footerLines;
                footerLocation  = _sourceRect.Bottom - footerLines;
            } while (footerLocation > _sourceRect.Top && primaryLocation > primaryImage.SourceRect.Top && primaryHashes[primaryLocation] == _hashes[footerLocation]);

            // Not interested in 1 line
            if (footerLines > 1)
            {
                // Remove the lines by removing the height
                _sourceRect = new NativeRect(_sourceRect.X, _sourceRect.Y, _sourceRect.Width, _sourceRect.Height - footerLines);
            }
            return(this);
        }