Ejemplo n.º 1
0
        public BitmapPixelData LockBitmapPixelData(BitmapLockMode lockMode, PixelFormat pixelFormat)
        {
            var bitmapData = _bitmap.LockBits(new Rectangle(0, 0, _bitmap.Width, _bitmap.Height),
                                              lockMode.ToGidImageLockMode(),
                                              pixelFormat.ToGdiPixelFormat());

            return(new GdiBitmapPixelData(bitmapData, lockMode));
        }
Ejemplo n.º 2
0
            public GdiBitmapPixelData(System.Drawing.Imaging.BitmapData bitmapData, BitmapLockMode lockMode)
                : base(lockMode)
            {
                _bitmapData = bitmapData;

                this.PixelFormat = bitmapData.PixelFormat.ToPixelFormat();
                this.Reserved    = bitmapData.Reserved;
                this.Stride      = bitmapData.Stride;
                this.Scan0       = bitmapData.Scan0;
                this.Width       = bitmapData.Width;
                this.Height      = bitmapData.Height;
            }
Ejemplo n.º 3
0
        static public System.Drawing.Imaging.ImageLockMode ToGidImageLockMode(this BitmapLockMode mode)
        {
            switch (mode)
            {
            case BitmapLockMode.ReadWrite:
                return(System.Drawing.Imaging.ImageLockMode.ReadWrite);

            case BitmapLockMode.WriteOnly:
                return(System.Drawing.Imaging.ImageLockMode.WriteOnly);

            default:
                return(System.Drawing.Imaging.ImageLockMode.ReadOnly);
            }
        }
Ejemplo n.º 4
0
        public BitmapPixelData LockBitmapPixelData(BitmapLockMode lockMode, PixelFormat pixelFormat)
        {
            if (_bitmap != null)
            {
                var pixelData = new SkiaBitmapPixelData(lockMode)
                {
                    Width       = _bitmap.Width,
                    Height      = _bitmap.Height,
                    Stride      = _bitmap.RowBytes,
                    PixelFormat = pixelFormat
                };

                if (lockMode == BitmapLockMode.Copy)
                {
                    pixelData.FreeMemory = true;
                    pixelData.Scan0      = Marshal.AllocHGlobal(_bitmap.ByteCount);
                    Marshal.Copy(_bitmap.Bytes, 0, pixelData.Scan0, _bitmap.ByteCount);
                }
                else if (pixelFormat == PixelFormat.Rgb24)
                {
                    pixelData.FreeMemory = true;
                    pixelData.Scan0      = Marshal.AllocHGlobal(_bitmap.RowBytes / 4 * _bitmap.Height * 3);
                    pixelData.Stride     = _bitmap.RowBytes / 4 * 3;

                    if (lockMode == BitmapLockMode.ReadOnly || lockMode == BitmapLockMode.ReadWrite)
                    {
                        pixelData.ReadFromArgb(_bitmap.GetPixels());
                    }
                }
                else
                {
                    pixelData.Scan0 = _bitmap.GetPixels();
                }

                return(pixelData);
            }

            return(null);
        }
Ejemplo n.º 5
0
 public SkiaBitmapPixelData(BitmapLockMode lockMode)
     : base(lockMode)
 {
     FreeMemory = false;
 }
Ejemplo n.º 6
0
 public BitmapPixelData(BitmapLockMode lockMode)
 {
     LockMode = lockMode;
 }