public void Resize(int width, int height) { this.Size = new RawSize(width, height); ReleaseResources(); SwapChain(); }
public LayeredBuffer(int width, int height, SKColorType colorType, SKAlphaType alphaType) { this.Size = new RawSize(width, height); this.ColorType = colorType; this.AlphaType = alphaType; Initialize(); }
public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref RawPoint pptDst, ref RawSize psize, IntPtr hdcSrc, ref RawPoint pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
/// <summary> /// /// </summary> /// <param name="bitmap"> /// /// </param> /// <param name="opacity"> /// Specifies an alpha transparency value to be used on the entire source /// bitmap. The SourceConstantAlpha value is combined with any per-pixel /// alpha values in the source bitmap. The value ranges from 0 to 255. If /// you set SourceConstantAlpha to 0, it is assumed that your image is /// transparent. When you only want to use per-pixel alpha values, set /// the SourceConstantAlpha value to 255 (opaque). /// </param> public void SelectBitmap(Bitmap bitmap, int opacity) { if (bitmap == null) { return; } // Does this bitmap contain an alpha channel? if (bitmap.PixelFormat != PixelFormat.Format32bppArgb && bitmap.PixelFormat != PixelFormat.Format32bppPArgb) { throw new ApplicationException("The bitmap must be 32bpp with alpha-channel."); } // Get device contexts IntPtr screenDc = GetDC(IntPtr.Zero); IntPtr memDc = CreateCompatibleDC(screenDc); IntPtr hBitmap = IntPtr.Zero; IntPtr hOldBitmap = IntPtr.Zero; try { // Get handle to the new bitmap and select it into the current // device context. hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); hOldBitmap = SelectObject(memDc, hBitmap); // Set parameters for layered window update. RawSize newSize = new RawSize(bitmap.Width, bitmap.Height); RawPoint sourceLocation = new RawPoint(0, 0); RawPoint newLocation = new RawPoint(this.Left, this.Top); BLENDFUNCTION blend = new BLENDFUNCTION(); blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = (byte)opacity; blend.AlphaFormat = AC_SRC_ALPHA; // Update the window. UpdateLayeredWindow( this.Handle, // Handle to the layered window screenDc, // Handle to the screen DC ref newLocation, // New screen position of the layered window ref newSize, // New size of the layered window memDc, // Handle to the layered window surface DC ref sourceLocation, // Location of the layer in the DC 0, // Color key of the layered window ref blend, // Transparency of the layered window ULW_ALPHA // Use blend as the blend function ); } finally { // Release device context. ReleaseDC(IntPtr.Zero, screenDc); if (hBitmap != IntPtr.Zero) { SelectObject(memDc, hOldBitmap); DeleteObject(hBitmap); } DeleteDC(memDc); } }