Пример #1
0
        static (Bmp bmp, bool valid) ShrinkToRect(Bmp bmp, Rectangle rect)
        {
            var newPixels = new BmpPixel[rect.Height, rect.Width];

            for (var y = rect.Y; y < rect.Bottom; y++)
            {
                for (var x = rect.X; x < rect.Right; x++)
                {
                    newPixels[y - rect.Y, x - rect.X] = bmp.Pixels[y, x];
                }
            }


            return(BmpParser.FromPixels(newPixels), newPixels.Length != 0);
        }
Пример #2
0
        public void BmpFromPixels(string fileName)
        {
            var bytes        = File.ReadAllBytes(fileName);
            var bmpFromBytes = BmpParser.Parse(bytes);
            var bmp          = BmpParser.FromPixels(bmpFromBytes.Pixels, bmpFromBytes.InfoHeader.BitPerPixel);

            bmp.InfoHeader.BitPerPixel = bmpFromBytes.InfoHeader.BitPerPixel;
            var outbytes = bmp.GetFileBytes();

            Assert.IsTrue(bytes.Length == outbytes.Length);

            for (var i = 0; i < bytes.Length; i++)
            {
                Assert.AreEqual(bytes[i], outbytes[i]);
            }
        }