代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsDisplayScale
{
class Program
{
static void Main(string[] args)
{
var scaling = GetScreenScalingFactor();
Bitmap bmp = TakingScreenshotEx1(scaling);
bmp.Save("Screenshot1.png", ImageFormat.Png);
}
[DllImport("gdi32.dll", EntryPoint = "GetDeviceCaps", SetLastError = true)]
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
enum DeviceCap
{
VERTRES = 10,
PHYSICALWIDTH = 110,
SCALINGFACTORX = 114,
DESKTOPVERTRES = 117,
// http://pinvoke.net/default.aspx/gdi32/GetDeviceCaps.html
}
private static double GetScreenScalingFactor()
{
var g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
var physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
var screenScalingFactor = (double)physicalScreenHeight / Screen.PrimaryScreen.Bounds.Height;//SystemParameters.PrimaryScreenHeight;
return screenScalingFactor;
}
private static Bitmap TakingScreenshotEx1(double scaling = 1)
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
var width = (int)(bounds.Width * scaling);
var height = (int)(bounds.Height * scaling);
Bitmap bitmap = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, new Size { Width = width, Height = height });
}
return bitmap;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。