Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

截图没有考虑屏幕缩放比例(DPI) #1574

Open
cadboy opened this issue Apr 22, 2024 · 1 comment
Open

截图没有考虑屏幕缩放比例(DPI) #1574

cadboy opened this issue Apr 22, 2024 · 1 comment

Comments

@cadboy
Copy link

cadboy commented Apr 22, 2024

Describe the bug

笔记本电脑一般屏幕缩放比例一般都是125%或者150%,截图的时候没有考虑这个问题,导致最后截取的图片范围比实际选择的区域要小很多

Steps to reproduce the bug

1、笔记本电脑缩放比例调节到150%
2、测试截图demo

Expected behavior

弹出的截图窗口中的图片比实际选择范围要小

Screenshots

No response

NuGet package version

HandyControl 3.4.0

IDE

Visual Studio 2022

Framework type

.Net Framework 4.7.2

Windows version

Windows 11 (22000)

Additional context

No response

@cadboy
Copy link
Author

cadboy commented Apr 22, 2024

可以这样修改下代码,但是需要引用Syatem.Drawing.dll,代码如下
ScreenshotWindow.cs
private void SaveScreenshot()
{
int top = _targetWindowRect.Top;
int left = _targetWindowRect.Left;
int width = _targetWindowRect.Width;
int height = _targetWindowRect.Height;
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
{
float dpiX = graphics.DpiX;
float dpiY = graphics.DpiY;
var scale = dpiX / 96.0;
top = (int) (top * scale);
left = (int) (left * scale);
width = (int) (width * scale);
height = (int) (height * scale);
}
var cb = new CroppedBitmap(_imageSource, new Int32Rect(left, top,width,height));
_screenshot.OnSnapped(cb);
Close();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant