HandyControl icon indicating copy to clipboard operation
HandyControl copied to clipboard

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

Open cadboy opened this issue 2 months ago • 1 comments

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 avatar Apr 22 '24 12:04 cadboy

可以这样修改下代码,但是需要引用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(); }

cadboy avatar Apr 22 '24 13:04 cadboy