Exemple #1
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;
            }
        }
Exemple #2
0
        public void Render(int[] vram)
        {
            //Console.WriteLine($"x1 {displayX1} x2 {displayX2} y1 {displayY1} y2 {displayY2}");

            int horizontalEnd = horizontalRes;
            int verticalEnd   = verticalRes;

            if (isVramViewer)
            {
                horizontalEnd = 1024;
                verticalEnd   = 512;

                Marshal.Copy(vram, 0, display.BitmapData, 0x80000);
            }
            else if (is24BitDepth)
            {
                blit24bpp(vram);
            }
            else
            {
                blit16bpp(vram);
            }

            fps++;

            using var deviceContext = new GdiDeviceContext(screen.Handle);

            Gdi32.StretchBlt(deviceContext, 0, 0, screen.Width, screen.Height,
                             display.DeviceContext, 0, 0, horizontalEnd, verticalEnd,
                             RasterOp.SRCCOPY);
        }
Exemple #3
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);
        }