gpt4 book ai didi

Windows10 中的 Delphi 桌面截图,GetDeviceCaps 问题

转载 作者:行者123 更新时间:2023-12-03 15:22:00 25 4
gpt4 key购买 nike

如何在 Windows10 中获取正确的屏幕尺寸来进行屏幕截图?它似乎得到了不正确的值(也许是 DPI 问题?)

// screenshot
b := TBitmap.Create;
DC := GetDC(GetDesktopWindow);
try
b.Width := GetDeviceCaps (DC, HORZRES) ;
b.Height := GetDeviceCaps (DC, VERTRES) ;
BitBlt(b.Canvas.Handle, 0, 0, b.Width, b.Height, DC, 0, 0, SRCCOPY) ;
finally
ReleaseDC (GetDesktopWindow, DC) ;
end;

在 4K 屏幕上只会捕获左上角的一小部分。

最佳答案

您需要使您的应用程序完全感知高 DPI,以便获得拍摄屏幕快照的正确值。

您可以通过将以下部分添加到应用程序 list 中来做到这一点

  <asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<小时/>

Windows 10 自定义 list 的完整示例

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>

<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>

<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>

<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>

<assemblyIdentity
type="win32"
name="MyApplication"
version="1.0.0.0"
processorArchitecture="*"/>

<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>

<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>

</assembly>
<小时/>

注意:Windows 10 引入了每显示器 DPI 感知。上面的 list 通过 true/PM 值(PM - 每个监视器)开启了这种意识。

自从 Delphi 在西雅图推出对每显示器 DPI 的支持以来,使用旧版本编译的应用程序将无法在 Windows 10 上每个显示器具有不同 DPI 设置的多显示器设置中正确缩放。具体取决于应用程序和用户的用途基地,你要么忍受这种行为,要么你必须升级到最新的Delphi(同样重要的是要注意,这是新功能,它确实有一些可能与你的情况相关或不相关的错误)

关于Windows10 中的 Delphi 桌面截图,GetDeviceCaps 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35587364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com