public FastBitmap(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }

            var bmp = BitmapFileFormat.FromFile(filename);

            if (!bmp.IsValid)
            {
                throw new ImagingException("Invalid File Format! " + filename);
            }

            if (bmp.IsUpsideDown)
            {
                bmp.ReverseScanLines();
            }

            byte[] bytes = bmp.GetBytes();

            _bitmapInfoHeader = Marshal.AllocHGlobal(bytes.Length);
            _dibSection       = _bitmapInfoHeader + (int)bmp.PixelArrayOffset;

            _pixels = (byte *)_dibSection.ToPointer();

            Marshal.Copy(bytes, 0, _bitmapInfoHeader, bytes.Length);

            Width  = bmp.ImageWidth;
            Height = Math.Abs(bmp.ImageHeight);

            Stride = (((bmp.ImageWidth * bmp.BitsPerPixel) + 31) / 32) * 4;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var bmp = BitmapFileFormat.FromFile("red.bmp");

            bmp.ReverseScanLines();

            bmp.Save("other.bmp");

            //using (var bmp = new FastBitmap("red.bmp"))
            //{
            //    Console.WriteLine(bmp.GetPixel(5, 5).Compare(new Pixel(0,0,0)));
            //    Console.WriteLine(bmp.GetPixel(9, 6).ToString());
            //    Console.WriteLine(bmp.GetPixel(2, 9).ToString());
            //    Console.WriteLine(bmp.GetPixel(3, 4).ToString());
            //}

            //Console.ReadLine();
        }