UpdateBitmap() private method

private UpdateBitmap ( int device, Bitmap bitmap, uint priority ) : ReturnValue
device int
bitmap Bitmap
priority uint
return ReturnValue
Ejemplo n.º 1
0
        public void UpdateBitmap(
            Bitmap bitmap,
            Priority priority,
            bool syncUpdate = false,
            bool syncCompleteWithinFrame = false)
        {
            if (!Opened)
            {
                throw new Exception("Not opened.");
            }
            if (bitmap.Width != BitmapWidth || bitmap.Height != BitmapHeight)
            {
                throw new ArgumentException("The bitmaps dimensions do not conform.");
            }
            var lgBitmap = new LgLcd.Bitmap {
                Format = _bitmapFormat,
                Pixels = new byte[BitmapWidth * BitmapHeight * BitmapBpp],
            };
            var bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, BitmapWidth, BitmapHeight),
                ImageLockMode.ReadOnly,
                _pixelFormat);

            Marshal.Copy(bitmapData.Scan0, lgBitmap.Pixels, 0, lgBitmap.Pixels.Length);
            bitmap.UnlockBits(bitmapData);
            var error = LgLcd.UpdateBitmap(
                Handle,
                lgBitmap,
                (uint)priority
                | (syncUpdate ? LgLcd.SyncUpdate : 0)
                | (syncCompleteWithinFrame ? LgLcd.SyncCompleteWithinFrame : 0));

            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                if (error == LgLcd.ReturnValue.ErrorDeviceNotConnected)
                {
                    throw new InvalidOperationException("The specified device has been disconnected.");
                }
                if (error == LgLcd.ReturnValue.ErrorAccessDenied)
                {
                    throw new InvalidAsynchronousStateException("Synchronous operation was not displayed on the LCD within the frame interval (30 ms).");
                }
                throw new Win32Exception((int)error);
            }
        }