Skip to content

Commit 34dab10

Browse files
authored
Merge pull request #4 from cloud-yd/master
截屏时获取系统DPI
2 parents e13e238 + ebfcba3 commit 34dab10

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/WPFDevelopers/Controls/ScreenCut/ScreenCut.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ void MoveAllRectangle(Point current)
183183

184184
System.Drawing.Bitmap CaptureScreen()
185185
{
186-
var bmpCaptured = new System.Drawing.Bitmap((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
186+
//修复缩放比例不等于100%(DPI不等于96)时,不能显示全屏的问题
187+
var source = PresentationSource.FromVisual(_canvas);
188+
double dpiX = source.CompositionTarget.TransformToDevice.M11; //96.0 *
189+
double dpiY = source.CompositionTarget.TransformToDevice.M22; //96.0 *
190+
191+
var bmpCaptured = new System.Drawing.Bitmap((int)(SystemParameters.PrimaryScreenWidth * dpiX), (int)(SystemParameters.PrimaryScreenHeight * dpiY), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
187192
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpCaptured))
188193
{
189194
g.SmoothingMode = SmoothingMode.AntiAlias;

0 commit comments

Comments
 (0)