Esempio n. 1
0
        public GdiBitmap(int width, int height)
        {
            Width  = width;
            Height = height;

            DeviceContext = Gdi32.CreateCompatibleDC(IntPtr.Zero);

            var bitmapHeader = new BitmapInfoHeader
            {
                biSize        = (uint)Marshal.SizeOf <BitmapInfoHeader>(),
                biWidth       = width,
                biHeight      = -height, // negative, top-down bitmap
                biPlanes      = 1,
                biBitCount    = (ushort)(8 * BytesPerPixel),
                biCompression = BitmapCompression.BI_RGB,
            };

            var bitmapInfo = new BitmapInfo
            {
                bmiHeader = bitmapHeader,
            };

            BitmapHandle = Gdi32.CreateDIBSection(DeviceContext, in bitmapInfo, ColorUsage.DIB_RGB_COLORS,
                                                  out BitmapData, IntPtr.Zero, 0);

            _oldObject = Gdi32.SelectObject(DeviceContext, BitmapHandle);
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                if (_oldObject != IntPtr.Zero)
                {
                    Gdi32.SelectObject(DeviceContext, _oldObject);
                }

                if (BitmapHandle != IntPtr.Zero)
                {
                    Gdi32.DeleteObject(BitmapHandle);
                }

                if (DeviceContext != IntPtr.Zero)
                {
                    Gdi32.DeleteDC(DeviceContext);
                }

                _disposed = true;
            }
        }
Esempio n. 3
0
        private void UpdateWindow()
        {
            using var deviceContext = new GdiDeviceContext(_renderPanel.Handle);

            Gdi32.StretchBlt(deviceContext, 0, 0, _renderPanel.Width, _renderPanel.Height,
                             _backBuffer.DeviceContext, 0, 0, BitmapWidth, BitmapHeight,
                             RasterOp.SRCCOPY);
        }