Exemplo n.º 1
0
        public void IsColumnBlank()
        {
            const int x = 4;

            Assert.IsFalse(src.IsColumnBlank(x, 0.05));

            for (int j = 0; j < src.Height; j++)
            {
                var clr = src.GetPixel(x, j);

                src.SetPixel(x, j, Color.FromArgb(0, clr.R, clr.G, clr.B));
            }

            Assert.IsTrue(src.IsColumnBlank(x, 0.05));
        }
Exemplo n.º 2
0
        public void Trim()
        {
            ImageData = new PixelBuffer(SourceData, SourceRect);

            Rectangle newRect = new Rectangle(0, 0, SourceRect.Width, SourceRect.Height);

            // trim the top
            for (int i = 0; i < ImageData.Height; i++)
            {
                if (ImageData.IsRowBlank(i))
                {
                    newRect.Y++;
                    newRect.Height--;
                }
                else
                {
                    break;
                }
            }

            if (newRect.Height == 0)
            {
                IsBlank = true;
                return;
            }

            // trim the bottom
            for (int i = ImageData.Height - 1; i >= 0; i--)
            {
                if (ImageData.IsRowBlank(i))
                {
                    newRect.Height--;
                }
                else
                {
                    break;
                }
            }

            // trim the left
            for (int i = 0; i < ImageData.Width; i++)
            {
                if (ImageData.IsColumnBlank(i))
                {
                    newRect.X++;
                    newRect.Width--;
                }
                else
                {
                    break;
                }
            }

            // trim the right
            for (int i = ImageData.Width - 1; i >= 0; i--)
            {
                if (ImageData.IsRowBlank(i))
                {
                    newRect.Width--;
                }
                else
                {
                    break;
                }
            }

            ImageData = new PixelBuffer(ImageData, newRect);
            Offset    = newRect.Location;
        }