Ejemplo n.º 1
0
            public void Overwrite(
                Gdi32.DeviceContextSafeHandle bitmapDC,
                Gdi32.DeviceContextSafeHandle windowDC,
                int windowClientLeft,
                int windowClientTop,
                int windowClientWidth,
                int windowClientHeight,
                uint windowDpi,
                uint zOrder)
            {
                if (windowClientWidth > 0 && windowClientHeight > 0)
                {
                    if (bitmap is null || bitmapWidth < windowClientWidth || bitmapHeight < windowClientHeight)
                    {
                        if (bitmap is null)
                        {
                            // Most of the time, windows don't resize, so save some space by not rounding up.
                            bitmapWidth  = windowClientWidth;
                            bitmapHeight = windowClientHeight;
                        }
                        else
                        {
                            // Round up to the nearest 256 pixels to minimize the number of times that bitmaps are
                            // reallocated.
                            bitmapWidth  = ((Math.Max(bitmapWidth, windowClientWidth) + 255) / 256) * 256;
                            bitmapHeight = ((Math.Max(bitmapHeight, windowClientHeight) + 255) / 256) * 256;

                            bitmap.Dispose();
                        }

                        bitmap = Gdi32.CreateDIBSection(windowDC, new()
                        {
                            bmiHeader =
                            {
                                biSize     = Marshal.SizeOf <Gdi32.BITMAPINFOHEADER>(),
                                biWidth    = bitmapWidth,
                                biHeight   =                             -bitmapHeight,
                                biPlanes   =                                         1,
                                biBitCount = BitsPerPixel,
                            },
                        }, Gdi32.DIB.RGB_COLORS, ppvBits: out _, hSection: IntPtr.Zero, offset: 0).ThrowLastErrorIfInvalid();
                    }

                    Gdi32.SelectObject(bitmapDC, bitmap).ThrowWithoutLastErrorAvailableIfInvalid(nameof(Gdi32.SelectObject));

                    if (!Gdi32.BitBlt(bitmapDC, 0, 0, windowClientWidth, windowClientHeight, windowDC, 0, 0, Gdi32.RasterOperation.SRCCOPY))
                    {
                        throw new Win32Exception();
                    }
                }

                WindowClientLeft   = windowClientLeft;
                WindowClientTop    = windowClientTop;
                WindowClientWidth  = windowClientWidth;
                WindowClientHeight = windowClientHeight;
                WindowDpi          = windowDpi;
                ZOrder             = zOrder;
            }
            public void AddFrame(
                Gdi32.DeviceContextSafeHandle bitmapDC,
                int windowClientLeft,
                int windowClientTop,
                int windowClientWidth,
                int windowClientHeight,
                uint windowDpi,
                uint zOrder)
            {
                if (windowDC is null)
                {
                    throw new InvalidOperationException("The window is closed.");
                }

                var frame = frames.GetNextRef() ??= new();

                frame.Overwrite(bitmapDC, windowDC, windowClientLeft, windowClientTop, windowClientWidth, windowClientHeight, windowDpi, zOrder);
            }
Ejemplo n.º 3
0
 public void Compose(Gdi32.DeviceContextSafeHandle bitmapDC, Gdi32.DeviceContextSafeHandle compositionDC, (int X, int Y) compositionOffset)