예제 #1
0
 private static Grid ConvertToGrayscale(WritableLockBitImage bitmap)
 {
     return(Grid.Op(
                (i, j) => ConvertColorToGrayscaleDouble(bitmap.GetPixel(i, j)),
                new Grid(bitmap.Width, bitmap.Height)
                ));
 }
        /// <summary>
        /// Copy constructor that clones the other WritableLockbitImage. This will clone all
        /// of the internal data from the passed in WritableLockBitImage, with the exception
        /// of whether it was locked.
        /// </summary>
        public WritableLockBitImage(WritableLockBitImage other)
        {
            _bitDepth = Image.GetPixelFormatSize(other.PixelFormat);
            if (_bitDepth != 8 && _bitDepth != 24 && _bitDepth != 32)
            {
                throw new ArgumentException("Only 8, 24, and 32 bit pixels are supported.");
            }
            _width      = other.Width;
            _height     = other.Height;
            _disposed   = _locked = false;
            _bitmap     = new Bitmap(Width, Height);
            _bitmapData = _bitmap.LockBits(new Rectangle(0, 0, Width, Height),
                                           ImageLockMode.ReadWrite,
                                           other.PixelFormat
                                           );

            // Copy over bitmap data manually
            for (int row = 0; row < Height; row++)
            {
                for (int col = 0; col < Width; col++)
                {
                    SetPixel(col, row, other.GetPixel(col, row));
                }
            }
        }