diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index 7c76b1c97..140eafb4f 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -368,6 +368,12 @@ public static bool IsWindows10OrGreater(int build = -1) return OSVersion.Major >= 10 && OSVersion.Build >= build; } + public static bool IsWindows11OrGreater(int build = -1) + { + build = Math.Max(22000, build); + return OSVersion.Major >= 10 && OSVersion.Build >= build; + } + public static bool IsDefaultInstallDir() { string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); diff --git a/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs b/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs index 807d3923c..1a9316778 100644 --- a/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs +++ b/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs @@ -90,18 +90,20 @@ public Bitmap CaptureWindowTransparent(IntPtr handle) return CaptureWindow(handle); } - Thread.Sleep(10); Application.DoEvents(); + Thread.Sleep(10); whiteBackground = CaptureRectangleNative(rect); form.BackColor = Color.Black; Application.DoEvents(); + Thread.Sleep(10); blackBackground = CaptureRectangleNative(rect); form.BackColor = Color.White; Application.DoEvents(); + Thread.Sleep(10); whiteBackground2 = CaptureRectangleNative(rect); @@ -204,20 +206,20 @@ private Bitmap CreateTransparentImage(Bitmap whiteBackground, Bitmap blackBackgr private void TrimShadow(Bitmap bitmap) { - int sizeLimit = 10; - int alphaLimit = 200; + int cornerSize = 10; + int alphaOffset = Helpers.IsWindows11OrGreater() ? 50 : 200; using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bitmap, true)) { - for (int i = 0; i < sizeLimit; i++) + for (int i = 0; i < cornerSize; i++) { int y = i; int width = bitmap.Width; // Left top - for (int x = 0; x < sizeLimit; x++) + for (int x = 0; x < cornerSize; x++) { - if (unsafeBitmap.GetPixel(x, y).Alpha < alphaLimit) + if (unsafeBitmap.GetPixel(x, y).Alpha < alphaOffset) { unsafeBitmap.ClearPixel(x, y); } @@ -228,9 +230,9 @@ private void TrimShadow(Bitmap bitmap) } // Right top - for (int x = width - 1; x > width - sizeLimit - 1; x--) + for (int x = width - 1; x > width - cornerSize - 1; x--) { - if (unsafeBitmap.GetPixel(x, y).Alpha < alphaLimit) + if (unsafeBitmap.GetPixel(x, y).Alpha < alphaOffset) { unsafeBitmap.ClearPixel(x, y); } @@ -243,9 +245,9 @@ private void TrimShadow(Bitmap bitmap) y = bitmap.Height - i - 1; // Left bottom - for (int x = 0; x < sizeLimit; x++) + for (int x = 0; x < cornerSize; x++) { - if (unsafeBitmap.GetPixel(x, y).Alpha < alphaLimit) + if (unsafeBitmap.GetPixel(x, y).Alpha < alphaOffset) { unsafeBitmap.ClearPixel(x, y); } @@ -256,9 +258,9 @@ private void TrimShadow(Bitmap bitmap) } // Right bottom - for (int x = width - 1; x > width - sizeLimit - 1; x--) + for (int x = width - 1; x > width - cornerSize - 1; x--) { - if (unsafeBitmap.GetPixel(x, y).Alpha < alphaLimit) + if (unsafeBitmap.GetPixel(x, y).Alpha < alphaOffset) { unsafeBitmap.ClearPixel(x, y); }