Use different TrimShadow alpha offset in Windows 11

This commit is contained in:
Jaex 2023-09-02 16:54:19 +03:00
parent 89de68d921
commit 38cfc1e6a9
2 changed files with 20 additions and 12 deletions

View file

@ -368,6 +368,12 @@ public static bool IsWindows10OrGreater(int build = -1)
return OSVersion.Major >= 10 && OSVersion.Build >= build; 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() public static bool IsDefaultInstallDir()
{ {
string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

View file

@ -90,18 +90,20 @@ public Bitmap CaptureWindowTransparent(IntPtr handle)
return CaptureWindow(handle); return CaptureWindow(handle);
} }
Thread.Sleep(10);
Application.DoEvents(); Application.DoEvents();
Thread.Sleep(10);
whiteBackground = CaptureRectangleNative(rect); whiteBackground = CaptureRectangleNative(rect);
form.BackColor = Color.Black; form.BackColor = Color.Black;
Application.DoEvents(); Application.DoEvents();
Thread.Sleep(10);
blackBackground = CaptureRectangleNative(rect); blackBackground = CaptureRectangleNative(rect);
form.BackColor = Color.White; form.BackColor = Color.White;
Application.DoEvents(); Application.DoEvents();
Thread.Sleep(10);
whiteBackground2 = CaptureRectangleNative(rect); whiteBackground2 = CaptureRectangleNative(rect);
@ -204,20 +206,20 @@ private Bitmap CreateTransparentImage(Bitmap whiteBackground, Bitmap blackBackgr
private void TrimShadow(Bitmap bitmap) private void TrimShadow(Bitmap bitmap)
{ {
int sizeLimit = 10; int cornerSize = 10;
int alphaLimit = 200; int alphaOffset = Helpers.IsWindows11OrGreater() ? 50 : 200;
using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bitmap, true)) 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 y = i;
int width = bitmap.Width; int width = bitmap.Width;
// Left top // 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); unsafeBitmap.ClearPixel(x, y);
} }
@ -228,9 +230,9 @@ private void TrimShadow(Bitmap bitmap)
} }
// Right top // 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); unsafeBitmap.ClearPixel(x, y);
} }
@ -243,9 +245,9 @@ private void TrimShadow(Bitmap bitmap)
y = bitmap.Height - i - 1; y = bitmap.Height - i - 1;
// Left bottom // 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); unsafeBitmap.ClearPixel(x, y);
} }
@ -256,9 +258,9 @@ private void TrimShadow(Bitmap bitmap)
} }
// Right bottom // 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); unsafeBitmap.ClearPixel(x, y);
} }