public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out RECT lpRect, int size);
public bool Equals(RECT Rectangle) { return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom; }
public RECT(RECT rectangle) : this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom) { }
private static extern int GdipBitmapApplyEffect(IntPtr bitmap, IntPtr effect, ref RECT rectOfInterest, bool useAuxData, IntPtr auxData, int auxDataSize);
/// <summary> /// Use the GDI+ blur effect on the bitmap /// </summary> /// <param name="destinationBitmap">Bitmap to apply the effect to</param> /// <param name="area">Rectangle to apply the blur effect to</param> /// <param name="radius">0-255</param> /// <param name="expandEdges">bool true if the edges are expanded with the radius</param> /// <returns>false if there is no GDI+ available or an exception occured</returns> public static bool ApplyBlur(Bitmap destinationBitmap, Rectangle area, int radius, bool expandEdges) { if (!IsBlurPossible(radius)) { return false; } IntPtr hBlurParams = IntPtr.Zero; IntPtr hEffect = IntPtr.Zero; try { // Create a BlurParams struct and set the values BlurParams blurParams = new BlurParams(); blurParams.Radius = radius; blurParams.ExpandEdges = expandEdges; // Allocate space in unmanaged memory hBlurParams = Marshal.AllocHGlobal(Marshal.SizeOf(blurParams)); // Copy the structure to the unmanaged memory Marshal.StructureToPtr(blurParams, hBlurParams, false); // Create the GDI+ BlurEffect, using the Guid int status = GdipCreateEffect(BlurEffectGuid, out hEffect); // Set the blurParams to the effect GdipSetEffectParameters(hEffect, hBlurParams, (uint)Marshal.SizeOf(blurParams)); // Somewhere it said we can use destinationBitmap.GetHbitmap(), this doesn't work!! // Get the private nativeImage property from the Bitmap IntPtr hBitmap = GetNativeImage(destinationBitmap); // Create a RECT from the Rectangle RECT rec = new RECT(area); // Apply the effect to the bitmap in the specified area GdipBitmapApplyEffect(hBitmap, hEffect, ref rec, false, IntPtr.Zero, 0); // Everything worked, return true return true; } catch (Exception ex) { isBlurEnabled = false; LOG.Error("Problem using GdipBitmapApplyEffect: ", ex); return false; } finally { try { if (hEffect != IntPtr.Zero) { // Delete the effect GdipDeleteEffect(hEffect); } if (hBlurParams != IntPtr.Zero) { // Free the memory Marshal.FreeHGlobal(hBlurParams); } } catch (Exception ex) { isBlurEnabled = false; LOG.Error("Problem cleaning up ApplyBlur: ", ex); } } }
public static extern int GetWindowRect(IntPtr hWnd, out RECT lpRect);
public static extern int GetClientRect(IntPtr hWnd, out RECT lpRect);
public static extern int GetClipBox(IntPtr hdc, out RECT lprc);