mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-24 01:00:27 +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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue