Ejemplo n.º 1
0
        public BitmapData LockBits(Size Size, ImageLockMode LockMode, PixelFormat Format)
        {
            var Data = Base.LockBits(new Rectangle(Point.Empty, Size), LockMode, Format);

            OnLockBits?.Invoke(Data);
            return(Data);
        }
Ejemplo n.º 2
0
 public BitmapCache(Bitmap bmp, ImageLockMode lockMode)
 {
     this.bmp      = bmp;
     PixelCount    = bmp.Width * bmp.Height;
     this.lockMode = lockMode;
     LockImage();
 }
Ejemplo n.º 3
0
        // Lock a region of this bitmap.  Use of this method is discouraged.
        // It assumes that managed arrays are fixed in place in memory,
        // which is true for ilrun, but maybe not other CLR implementations.
        // We also assume that "format" is the same as the bitmap's real format.
        public unsafe BitmapData LockBits
            (Rectangle rect, ImageLockMode flags,
            PixelFormat format)
        {
            BitmapData bitmapData = new BitmapData();

            bitmapData.Width       = rect.Width;
            bitmapData.Height      = rect.Height;
            bitmapData.PixelFormat = format;
            if (dgImage != null)
            {
                Frame frame = dgImage.GetFrame(0);
                if (frame != null)
                {
                    if (format != PixelFormat)
                    {
                        frame = frame.Reformat(format);
                    }
                    bitmapData.Stride = frame.Stride;
                    byte[] data = frame.Data;
                    bitmapData.dataHandle = GCHandle.Alloc(data);

                    int offset = rect.X * GetPixelFormatSize(format) / 8;
                    // TODO: will GCHandle.AddrOfPinnedObject work more
                    //       portably across GCs ?
                    fixed(byte *pixel = &(data[rect.Y * frame.Stride]))
                    {
                        bitmapData.Scan0 = (IntPtr)(void *)(pixel + offset);
                    }
                }
            }
            return(bitmapData);
        }
Ejemplo n.º 4
0
        public BitmapData LockBits(Rectangle Area, ImageLockMode LockMode, PixelFormat Format, BitmapData OriData)
        {
            var Data = Base.LockBits(Area, LockMode, Format, OriData);

            OnLockBits?.Invoke(Data);
            return(Data);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageBuffer"/> class.
        /// </summary>
        public ImageBuffer(Bitmap bitmap, ImageLockMode lockMode)
        {
            // locks the image data
            this.bitmap = bitmap;
            this.lockMode = lockMode;

            // gathers the informations
            Width = bitmap.Width;
            Height = bitmap.Height;
            PixelFormat = bitmap.PixelFormat;
            IsIndexed = PixelFormat.IsIndexed();
            BitDepth = PixelFormat.GetBitDepth();
            BytesPerPixel = Math.Max(1, BitDepth >> 3);

            // determines the bounds of an image, and locks the data in a specified mode
            Rectangle bounds = Rectangle.FromLTRB(0, 0, Width, Height);

            // locks the bitmap data
            lock (bitmap) bitmapData = bitmap.LockBits(bounds, lockMode, PixelFormat);

            // creates internal buffer
            Stride = bitmapData.Stride < 0 ? -bitmapData.Stride : bitmapData.Stride;
            Size = Stride*Height;

            // precalculates the offsets
            Precalculate();
        }
Ejemplo n.º 6
0
 public BitmapLocker(Bitmap bitmap, ImageLockMode lockMode = ImageLockMode.ReadWrite)
 {
     this.Bitmap = bitmap;
     // GDI+ still lies to us - the return format is BGR, NOT RGB.
     this.BitmapData = this.Bitmap.LockBits(
         new Rectangle(0, 0, this.Bitmap.Width, this.Bitmap.Height), lockMode, PixelFormat.Format24bppRgb);
 }
Ejemplo n.º 7
0
        public BitmapTool(Bitmap source, bool isReadOnly = false, bool isImmediateInitPixels = false)
        {
            this.Source = source;
            // get source bitmap pixel format size
            Depth = Image.GetPixelFormatSize(source.PixelFormat);
            // Check if bpp (Bits Per Pixel) is 8, 24, or 32
            if (Depth != 8 && Depth != 24 && Depth != 32)
            {
                throw new ArgumentException("Only 8, 24 and 32 bpp images are supported.");
            }
            // Get width and height of bitmap
            Width  = source.Width;
            Height = source.Height;
            // get total locked pixels count
            PixelCount = Width * Height;
            // Create rectangle to lock
            Rect = new Rectangle(0, 0, Width, Height);
            // create byte array to copy pixel values
            Step          = Depth / 8;
            PixelLength   = PixelCount * Step;
            Pixels        = new byte[PixelLength];
            imageLockMode = isReadOnly ? ImageLockMode.ReadOnly : imageLockMode;

            if (isImmediateInitPixels)
            {
                ReadLockBits();
                WriteUnlockBits();
            }
        }
Ejemplo n.º 8
0
        public BitmapPlus(Bitmap bitmap, ImageLockMode lockMode)
        {
            Source = bitmap;
            Cols   = Source.Width;
            Rows   = Source.Height;

            _pixelCount  = Source.Width * Source.Height;
            _imgLockMode = lockMode;

            Rectangle lockRectangle = new Rectangle(0, 0, Source.Width, Source.Height);

            _depth = Image.GetPixelFormatSize(Source.PixelFormat);

            if (_depth != 8 && _depth != 24 && _depth != 32)
            {
                throw new ArgumentException("Only 8, 24 and 32 bpp images are supported.");
            }

            Data = Source.LockBits(lockRectangle, _imgLockMode, Source.PixelFormat);

            _colorStep   = _depth / 8;
            Pixels       = new byte[_pixelCount * _colorStep];
            imagePointer = Data.Scan0;

            // Copy data from pointer to array
            Marshal.Copy(imagePointer, Pixels, 0, Pixels.Length);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="bitmap">位图</param>
        /// <param name="flags">读写模式</param>
        /// <param name="format">像素格式</param>
        public LockedBitmapData(Bitmap bitmap, ImageLockMode flags, PixelFormat format)
        {
            this.m_Bitmap = bitmap;
            Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

            this.m_BitmapData = this.m_Bitmap.LockBits(rect, flags, format);
        }
Ejemplo n.º 10
0
        public LockData(Bitmap bmp, Rectangle rect, ImageLockMode mode = ImageLockMode.ReadOnly)
        {
            Data = bmp.LockBits(rect, mode, bmp.PixelFormat);

            bitmap = bmp;
            bytes  = bmp.BytesPerPixel();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageBuffer"/> class.
        /// </summary>
        public ImageBuffer(Bitmap bitmap, ImageLockMode lockMode)
        {
            // locks the image data
            this.bitmap   = bitmap;
            this.lockMode = lockMode;

            // gathers the informations
            Width         = bitmap.Width;
            Height        = bitmap.Height;
            PixelFormat   = bitmap.PixelFormat;
            IsIndexed     = PixelFormat.IsIndexed();
            BitDepth      = PixelFormat.GetBitDepth();
            BytesPerPixel = Math.Max(1, BitDepth >> 3);

            // determines the bounds of an image, and locks the data in a specified mode
            Rectangle bounds = Rectangle.FromLTRB(0, 0, Width, Height);

            // locks the bitmap data
            lock (bitmap) bitmapData = bitmap.LockBits(bounds, lockMode, PixelFormat);

            // creates internal buffer
            Stride = bitmapData.Stride < 0 ? -bitmapData.Stride : bitmapData.Stride;
            Size   = Stride * Height;

            // precalculates the offsets
            Precalculate();
        }
Ejemplo n.º 12
0
        public LockData(Bitmap bmp, Rectangle rect, ImageLockMode mode = ImageLockMode.ReadOnly)
        {
            Data = bmp.LockBits(rect, mode, bmp.PixelFormat);

            bitmap = bmp;
            bytes = bmp.BytesPerPixel();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Begin editing an image.
        /// </summary>
        public static byte[] Begin(Bitmap bitmap, ImageLockMode lockMode, out BitmapData bmpData)
        {
            // Lock full image
            Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

            // Lock the bitmap's bits while we change them.
            bmpData = bitmap.LockBits(rect, lockMode, bitmap.PixelFormat);

            // Create length with number of bytes in image
            byte[] rgbValues = new byte[bmpData.GetByteCount()];

            // Copy the RGB values into the array.
            Marshal.Copy(bmpData.Scan0, rgbValues, 0, rgbValues.Length);

            // Check if monochrome
            if (bitmap.PixelFormat == PixelFormat.Format1bppIndexed)
            {
                // Adjust stride
                bmpData.Stride *= Constants.BitsPerByte;

                // Convert each bit to a separate byte
                return(ImageBytes.BytesToBits(rgbValues));
            }
            else
            {
                return(rgbValues);
            }
        }
Ejemplo n.º 14
0
 internal DisposableImageData(Bitmap bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format)
 {
     if (bitmap == null)
         throw new ArgumentNullException("bitmap");
     _bitmap = bitmap;
     _data = bitmap.LockBits(rect, flags, format);
 }
 public BitmapLocker(Bitmap bitmap, ImageLockMode lockMode = ImageLockMode.ReadWrite)
 {
     this.Bitmap = bitmap;
     // GDI+ still lies to us - the return format is BGR, NOT RGB. 
     this.BitmapData = this.Bitmap.LockBits(
         new Rectangle(0, 0, this.Bitmap.Width, this.Bitmap.Height), lockMode, PixelFormat.Format24bppRgb);
 }
Ejemplo n.º 16
0
 public BitmapCache(Bitmap bmp, ImageLockMode lockMode)
 {
     this.bmp = bmp;
     PixelCount = bmp.Width * bmp.Height;
     this.lockMode = lockMode;
     LockImage();
 }
Ejemplo n.º 17
0
 public FastBitmap(Bitmap bitmap, ImageLockMode lockMode, PixelFormat pixelFormat)
 {
     _bitmap = bitmap;
     Data    = bitmap.LockBits(new Rectangle(new Point(0, 0), bitmap.Size), lockMode, pixelFormat);
     Bpp     = Data.Stride / Data.Width;
     Start   = (byte *)Data.Scan0;
 }
Ejemplo n.º 18
0
        public UnsafeBitmap(Bitmap bitmap, bool lockBitmap = false, ImageLockMode imageLockMode = ImageLockMode.ReadWrite)
        {
            this.bitmap = bitmap;
            Width = bitmap.Width;
            Height = bitmap.Height;

            if (lockBitmap) Lock(imageLockMode);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 鎖定圖片並傳回Scan0記憶體位置
        /// </summary>
        /// <param name="imageLockMode">縮定模式</param>
        /// <returns>Scan0記憶體位置</returns>
        public IntPtr LockBitsAndGetScan0(ImageLockMode imageLockMode)
        {
            UnlockBits();
            Rectangle rect = new Rectangle(0, 0, Width, Height);

            _bitmapData = Image.LockBits(rect, imageLockMode, PixelFormat.Format32bppArgb);
            return(_bitmapData.Scan0);
        }
        public static FastBitmap FastLock(this Bitmap bitmap, ImageLockMode mode)
        {
            var fast = new FastBitmap(bitmap);

            fast.Lock(mode);

            return(fast);
        }
Ejemplo n.º 21
0
        public BitmapLocker(Bitmap bitmap, ImageLockMode mode)
        {
            Validate.IsNotNull(bitmap, "bitmap");
            _bitmap = bitmap;
            Rectangle rect = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height);

            _bitmapData = bitmap.LockBits(rect, mode, _bitmap.PixelFormat);
        }
Ejemplo n.º 22
0
        public DirectBitmapAccess([NotNull] Bitmap bitmap, ImageLockMode lockMode, bool premultiplied)
        {
            _bitmap = bitmap;
            var rect   = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var format = premultiplied ? PixelFormat.Format32bppPArgb : PixelFormat.Format32bppArgb;

            _bitmapData = bitmap.LockBits(rect, lockMode, format);
        }
Ejemplo n.º 23
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
        {
            Contract.Ensures(Contract.Result <BitmapData>() != null);

            BitmapData bitmapData = new BitmapData();

            return(LockBits(rect, flags, format, bitmapData));
        }
Ejemplo n.º 24
0
 public void LockHostBitmap(ImageLockMode imageLockMode)
 {
     ImageLockMode = imageLockMode;
     BitmapData    = LockEntireBitmap(Bitmap, imageLockMode);
     if (ImageLockMode == ImageLockMode.ReadWrite || imageLockMode == ImageLockMode.WriteOnly)
     {
     }
 }
Ejemplo n.º 25
0
            // Constructor locks the bitmap.
            public PixelAccessor(Bitmap bitmap, ImageLockMode mode, Rectangle?region = null)
            {
                this.bitmap = bitmap;

                Region = region.GetValueOrDefault(new Rectangle(0, 0, bitmap.Width, bitmap.Height));

                data = bitmap.LockBits(Region, mode, PixelFormat.Format32bppArgb);
            }
Ejemplo n.º 26
0
 private BitmapLocker(Bitmap bitmapToLock, ImageLockMode lockMode, Rectangle rect)
 {
     bitmap        = bitmapToLock;
     this.lockMode = lockMode;
     areaToLock    = rect;
     format        = bitmap.PixelFormat;
     Lock();
 }
Ejemplo n.º 27
0
        /// <summary>
        /// ビットマップとフラグをもとに BitmapController クラスのインスタンスを初期化します。
        /// </summary>
        /// <param name="bitmap">元となるビットマップ。</param>
        /// <param name="flags">メモリロックフラグ。</param>
        public BitmapController(Bitmap bitmap, ImageLockMode flags)
        {
            if (bitmap == null)
                throw new ArgumentNullException("bitmap");

            this.bitmap = bitmap;
            this.data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), flags, PixelFormat.Format32bppArgb);
            this.scan0 = data.Scan0;
        }
Ejemplo n.º 28
0
 public void Lock(ImageLockMode imageLockMode = ImageLockMode.ReadWrite)
 {
     if (!IsLocked)
     {
         IsLocked = true;
         bitmapData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), imageLockMode, PixelFormat.Format32bppArgb);
         Pointer = (ColorBgra*)bitmapData.Scan0.ToPointer();
     }
 }
Ejemplo n.º 29
0
 protected unsafe Texture(Bitmap bitmap, ImageLockMode imageLockMode)
 {
     _bitmap     = bitmap;
     _width      = _bitmap.Width;
     _height     = _bitmap.Height;
     _bitmapData = _bitmap.LockBits(new Rectangle(0, 0, _width, _height), imageLockMode,
                                    PixelFormat.Format32bppRgb);
     _data = (int *)_bitmapData.Scan0;
 }
Ejemplo n.º 30
0
 public void Lock(ImageLockMode imageLockMode = ImageLockMode.ReadWrite)
 {
     if (!IsLocked)
     {
         IsLocked   = true;
         bitmapData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), imageLockMode, PixelFormat.Format32bppArgb);
         Pointer    = (ColorBgra *)bitmapData.Scan0.ToPointer();
     }
 }
Ejemplo n.º 31
0
        private byte[] getImageBytes(Bitmap image, ImageLockMode lockMode, out BitmapData bmpData)
        {
            bmpData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                     lockMode, image.PixelFormat);
            byte[] imageBytes = new byte[bmpData.Stride * image.Height];
            Marshal.Copy(bmpData.Scan0, imageBytes, 0, imageBytes.Length);

            return(imageBytes);
        }
Ejemplo n.º 32
0
            public BitmapDataReleaser(Bitmap bitmap, Rectangle rectangle, PixelFormat?pixelFormat = null, ImageLockMode imageLockMode = ImageLockMode.ReadOnly)
            {
                Bitmap        = bitmap;
                Rectangle     = rectangle;
                PixelFormat   = pixelFormat ?? bitmap.PixelFormat;
                ImageLockMode = imageLockMode;

                Data = bitmap.LockBits(Rectangle, ImageLockMode, PixelFormat);
            }
Ejemplo n.º 33
0
 internal DisposableImageData(Bitmap bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format)
 {
     if (bitmap == null)
     {
         throw new ArgumentNullException("bitmap");
     }
     _bitmap = bitmap;
     _data   = bitmap.LockBits(rect, flags, format);
 }
Ejemplo n.º 34
0
        BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            Status status = GDIPlus.GdipBitmapLockBits(nativeObject, ref rect, flags, format, bitmapData);

            //NOTE: scan0 points to piece of memory allocated in the unmanaged space
            GDIPlus.CheckStatus(status);

            return(bitmapData);
        }
Ejemplo n.º 35
0
 private BitmapData GetBitmapData(
     Bitmap bitmap, ImageLockMode lockMode)
 {
     return(bitmap.LockBits(
                new System.Drawing.Rectangle(0, 0,
                                             bitmap.Width, bitmap.Height),
                lockMode,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb));
 }
Ejemplo n.º 36
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            var gprect = new GPRECT(rect);
            int status = SafeNativeMethods.Gdip.GdipBitmapLockBits(new HandleRef(this, nativeImage), ref gprect,
                                                                   flags, format, bitmapData);

            SafeNativeMethods.Gdip.CheckStatus(status);

            return(bitmapData);
        }
Ejemplo n.º 37
0
        public void LockBits(Rectangle area, ImageLockMode lockMode = ImageLockMode.ReadWrite)
        {
            if (IsLocked)
            {
                throw new ArgumentException("This source already has locked bits");
            }

            Source   = _image.LockBits(area, lockMode, _image.PixelFormat);
            IsLocked = true;
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Locks the bitmap to start the bitmap operations
 /// </summary>
 /// <param name="lockMode">The lock mode to use on the bitmap</param>
 /// <param name="rect">The rectangle to lock</param>
 /// <param name="pixelFormat">A pixel format to use when locking the underlying bitmap</param>
 /// <returns>A fast bitmap locked struct that will unlock the underlying bitmap after disposal</returns>
 /// <exception cref="System.ArgumentException">The provided region is invalid</exception>
 /// <exception cref="System.Exception">The locking operation in the underlying bitmap failed</exception>
 /// <exception cref="InvalidOperationException">The bitmap region is already locked</exception>
 /// <exception cref="ArgumentException"><see cref="!:pixelFormat"/> is not a 32bpp format</exception>
 private FastBitmapLocker Lock(ImageLockMode lockMode, Rectangle rect, PixelFormat pixelFormat)
 {
     // Lock the bitmap's bits
     _bitmapData   = _bitmap.LockBits(rect, lockMode, pixelFormat);
     _scan0        = (int *)_bitmapData.Scan0;
     Stride        = _bitmapData.Stride / BytesPerPixel;
     StrideInBytes = _bitmapData.Stride;
     Locked        = true;
     return(new FastBitmapLocker(this));
 }
Ejemplo n.º 39
0
        private void Initialize(Bitmap bmp, ImageLockMode imageLockMode)
        {
            bitmap = bmp;

            depth = System.Drawing.Image.GetPixelFormatSize(bitmap.PixelFormat);
            if (depth != 8 && depth != 24 && depth != 32)
            {
                throw new ArgumentException("Only 8, 24 and 32 bpp images are supported.");
            }

            bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                imageLockMode, PixelFormat.Format32bppArgb);
        }
Ejemplo n.º 40
0
		public FastBitmap(Bitmap bitmap, ImageLockMode lockMode, bool cleanSlate = false)
		{
			int byteCount = bitmap.Width * bitmap.Height * bpp;

			_bytes  = new byte[byteCount];
			_bitmap = bitmap;

			_bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), lockMode, 
				PixelFormat.Format32bppArgb);

			if (!cleanSlate)
				Marshal.Copy(_bitmapData.Scan0, _bytes, 0, byteCount);
		}
Ejemplo n.º 41
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
        {
            if (this.InternalBitmapData == null)
            {
                var x = this.InternalContext.getImageData(0, 0, this.Width, this.Height);

                var p = new __IntPtr
                {
                    PointerToUInt8 = x.data
                };

                this.InternalBitmapData = new __BitmapData
                {
                    Scan0 = (IntPtr)(object)p,
                    InternalImageData = x
                };
            }

            return (BitmapData)(object)this.InternalBitmapData;
        }
Ejemplo n.º 42
0
 public static DisposableImageData LockBitsDisposable(this Bitmap bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format)
 {
     return new DisposableImageData(bitmap, rect, flags, format);
 }
Ejemplo n.º 43
0
 public BitmapData LockBits(RectangleF rect, ImageLockMode flags, PixelFormat format)
 {
     throw new NotImplementedException ();
 }
Ejemplo n.º 44
0
            public BitmapDataReleaser(Bitmap bitmap, Rectangle rectangle, PixelFormat? pixelFormat = null, ImageLockMode imageLockMode = ImageLockMode.ReadOnly)
            {
                this.Bitmap = bitmap;
                this.Rectangle = rectangle;
                this.PixelFormat = pixelFormat ?? bitmap.PixelFormat;
                this.ImageLockMode = imageLockMode;

                this.Data = bitmap.LockBits(Rectangle, ImageLockMode, PixelFormat);
            }
Ejemplo n.º 45
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format) {
            Contract.Ensures(Contract.Result<BitmapData>() != null);

            BitmapData bitmapData = new BitmapData();

            return LockBits(rect, flags, format, bitmapData);
        }
Ejemplo n.º 46
0
 public static unsafe void UnsafeTransformation(this Bitmap b, UnsafeImageTransformation transformer, PixelFormat format, ImageLockMode m)
 {
     BitmapData bits = b.LockBits(b.GetImageSizeRectangle(), m, format);
       unsafe
       {
     byte* input = (byte*)bits.Scan0;
     transformer(bits, input);
       }
       b.UnlockBits(bits);
 }
Ejemplo n.º 47
0
 public static BitmapDataReleaser Lock(this Bitmap bitmap, Rectangle rect, PixelFormat pixelFormat, ImageLockMode imageLockMode = ImageLockMode.ReadOnly)
 {
     return new BitmapDataReleaser(bitmap, rect, pixelFormat, imageLockMode);
 }
Ejemplo n.º 48
0
        public BitmapData LockBits(Rectangle rectangle, ImageLockMode readOnly, PixelFormat pixelFormat)
        {
            switch (pixelFormat)
            {
                case PixelFormat.Alpha:
                case PixelFormat.PAlpha:
                case PixelFormat.Indexed:
                case PixelFormat.Undefined:
                    throw new ArgumentException("LockBits method only applicable to pixel formats with prefix Format",
                        "pixelFormat");
            }

            if (!pixelFormat.Equals(_pixelFormat))
                throw new ArgumentException(String.Format("Bitmap.PixelFormat = {0}", _pixelFormat), "pixelFormat");

            return new BitmapData(_width, _height, _stride, _pixelFormat, _scan0);
        }
Ejemplo n.º 49
0
		private byte[] HashLock (Bitmap bmp, int width, int height, PixelFormat fmt, ImageLockMode mode)
		{
			int len = bmp.Width * bmp.Height * 4;
			byte[] pixels = new byte[len];
			BitmapData bd = bmp.LockBits (new Rectangle (0, 0, width, height), mode, fmt);
			try {
				int index = 0;
				int bbps = Image.GetPixelFormatSize (fmt);
				long pos = bd.Scan0.ToInt64 ();
				byte[] btv = new byte[1];
				for (int y = 0; y < bd.Height; y++) {
					for (int x = 0; x < bd.Width; x++) {

						/* Read the pixels*/
						for (int bt = 0; bt < bbps / 8; bt++, index++) {
							long cur = pos;
							cur += y * bd.Stride;
							cur += x * bbps / 8;
							cur += bt;
							Marshal.Copy ((IntPtr) cur, btv, 0, 1);
							pixels[index] = btv[0];

							/* Make change of all the colours = 250 to 10*/
							if (btv[0] == 250) {
								btv[0] = 10;
								Marshal.Copy (btv, 0, (IntPtr) cur, 1);
							}
						}
					}
				}

				for (int i = index; i < len; i++)
					pixels[index] = 0;
			}
			finally {
				bmp.UnlockBits (bd);
			}
			return MD5.Create ().ComputeHash (pixels);
		}
Ejemplo n.º 50
0
 public System.Drawing.Imaging.BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format) { return DATA.LockBits(rect, flags, format); }
Ejemplo n.º 51
0
        protected bool Lock(ImageLockMode mode, Rectangle rectangle)
        {
            // No texture bounds
            if (ID == -1 || IsLocked)
                return false;

            Data = new byte[rectangle.Width * rectangle.Height * 4];

            LockMode = mode;
            IsLocked = true;

            if (mode == ImageLockMode.WriteOnly)
                return true;

            GL.BindTexture(TextureTarget.Texture2D, ID);

            // Get the whole texture
            if (rectangle == new Rectangle(Point.Empty, Size))
            {
                GL.GetTexImage<byte>(TextureTarget.Texture2D, 0, (OpenTK.Graphics.OpenGL.PixelFormat)PixelFormat, PixelType.UnsignedByte, Data);
            }
            else
            {
                GL.ReadPixels(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, (OpenTK.Graphics.OpenGL.PixelFormat)PixelFormat, PixelType.UnsignedByte, Data);
            }
            return true;
        }
Ejemplo n.º 52
0
 public void LockHostBitmap(ImageLockMode imageLockMode)
 {
     ImageLockMode = imageLockMode;
     BitmapData = LockEntireBitmap(Bitmap, imageLockMode);
     if (ImageLockMode == ImageLockMode.ReadWrite || imageLockMode == ImageLockMode.WriteOnly)
     {
     }
 }
Ejemplo n.º 53
0
 protected BitmapData LockEntireBitmap( Bitmap bitmap, ImageLockMode imageLockMode )
 {
     Rectangle r = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
     return bitmap.LockBits(r, imageLockMode, PixelFormat.Format32bppArgb);
 }
Ejemplo n.º 54
0
 public void UnlockHostBitmap()
 {
     Bitmap.UnlockBits(BitmapData);
     BitmapData = null;
     ImageLockMode = ImageLockMode.ReadWrite;
 }
Ejemplo n.º 55
0
        public void UnlockBits(BitmapData data)
        {
            if (bitsLockMode == ImageLockMode.ReadOnly)
            {
                pinnedScanArray.Free ();
                bitsLockMode = 0;
                return;
            }

            //int destStride = data.Width * (NativeCGImage.BitsPerPixel / NativeCGImage.BitsPerComponent);
            int destStride = data.Stride;

            // Declare our size
            var scanLength  = destStride * Height;

            // This is fine here for now until we support other formats but right now it is RGBA
            var pixelSize = GetPixelFormatComponents (data.PixelFormat);

            if (pixelSize == 4)
                Convert_BGRA_8888_To_P_RGBA_8888 (data.Scan0, bitmapBlock, scanLength);
            else
                Convert_BGR_888_To_P_RGBA_8888 (data.Scan0, bitmapBlock, scanLength);

            // Create a bitmap context from the pixel data
            var bitmapContext = CreateCompatibleBitmapContext (data.Width, data.Height, data.PixelFormat, bitmapBlock);

            // Dispose of the prevous image that is allocated.
            NativeCGImage.Dispose ();

            // Get the image from the bitmap context.
            NativeCGImage = bitmapContext.ToImage ();

            // Dispose of the bitmap context as it is no longer needed
            bitmapContext.Dispose ();

            // we need to free our pointer
            pinnedScanArray.Free();
            bitsLockMode = 0;
        }
Ejemplo n.º 56
0
 protected bool Lock(ImageLockMode mode)
 {
     return Lock(mode, new Rectangle(Point.Empty, Size));
 }
Ejemplo n.º 57
0
        public BitmapData LockBits(RectangleF rect, ImageLockMode flags, PixelFormat pixelFormat)
        {
            BitmapData bitmapData = new BitmapData ();

            if (!ConversionHelpers.sTablesInitialized)
                ConversionHelpers.CalculateTables ();

            // Calculate our strides
            int srcStride = (int)rect.Width * (NativeCGImage.BitsPerPixel / NativeCGImage.BitsPerComponent);

            int numOfComponents = GetPixelFormatComponents(pixelFormat);
            int stride = (int)rect.Width * numOfComponents;

            // Calculate our lengths
            int srcScanLength  = (int)(Math.Abs(srcStride) * rect.Height);
            int scanLength = (int)(Math.Abs(stride) * rect.Height);

            // Declare an array to hold the scan bytes of the bitmap.
            byte[] scan0 = new byte[scanLength];
            pinnedScanArray = GCHandle.Alloc(scan0, GCHandleType.Pinned);
            bitmapData.Scan0 = pinnedScanArray.AddrOfPinnedObject();

            byte[] srcScan0 = new byte[srcScanLength];

            IntPtr ptr = bitmapBlock;
            if (ptr == IntPtr.Zero)
            {
                var pData = NativeCGImage.DataProvider;
                var nData = pData.CopyData ();
                ptr = nData.Bytes;
            }
            // Copy the RGB values into the scan array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, srcScan0, 0, srcScanLength);

            if (numOfComponents == 4)
                Convert_P_RGBA_8888_To_BGRA_8888 (ref scan0, srcScan0);
            else
                Convert_P_RGBA_8888_To_BGR_888 (ref scan0, srcScan0);

            // We need to support sub rectangles.
            if (rect != new RectangleF (new PointF (0, 0), physicalDimension))
            {
                throw new NotImplementedException("Sub rectangles of bitmaps not supported yet.");
            }
            else
            {
                bitmapData.Height = (int)rect.Height;
                bitmapData.Width = (int)rect.Width;
                bitmapData.PixelFormat = pixelFormat;

                bitmapData.Stride = stride;
            }

            return bitmapData;
        }
Ejemplo n.º 58
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            Contract.Ensures(Contract.Result<BitmapData>() != null);

            GPRECT gprect = new GPRECT(rect);
            int status = SafeNativeMethods.Gdip.GdipBitmapLockBits(new HandleRef(this, nativeImage), ref gprect,
                                                    flags, format, bitmapData);

            if (status != SafeNativeMethods.Gdip.Ok)
                throw SafeNativeMethods.Gdip.StatusException(status);

            return bitmapData;
        }
Ejemplo n.º 59
0
 internal DisposableImageData(Bitmap bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format)
 {
     _bitmap = bitmap;
     _data = bitmap.LockBits(rect, flags, format);
 }
Ejemplo n.º 60
0
		internal static extern Status GdipBitmapLockBits (IntPtr bmp, ref Rectangle rc, ImageLockMode flags, PixelFormat format, [In, Out] BitmapData bmpData);