mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-30 20:20:34 +12:00
Use different TrimShadow alpha offset in Windows 11
This commit is contained in:
parent
89de68d921
commit
38cfc1e6a9
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue