From fdcb07ae6504e114ce2eab7fe1d51cd579b05473 Mon Sep 17 00:00:00 2001 From: snltty <1069410172@qq.com> Date: Fri, 13 Oct 2023 23:00:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BA=B9=E7=90=86=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E5=87=8F=E5=B0=91CPU=E4=BD=BF=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E5=8A=A0=E9=80=9F=E6=88=AA=E5=B1=8F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reports/screen/sharpDX/DesktopDuplicator.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmonitor/server/client/reports/screen/sharpDX/DesktopDuplicator.cs b/cmonitor/server/client/reports/screen/sharpDX/DesktopDuplicator.cs index be463c56..31a63370 100644 --- a/cmonitor/server/client/reports/screen/sharpDX/DesktopDuplicator.cs +++ b/cmonitor/server/client/reports/screen/sharpDX/DesktopDuplicator.cs @@ -31,7 +31,10 @@ namespace cmonitor.server.client.reports.screen.sharpDX public DesktopDuplicator(int whichGraphicsCardAdapter, int whichOutputDevice) { - InitCapture(whichGraphicsCardAdapter, whichOutputDevice); + if (OperatingSystem.IsWindows()) + { + InitCapture(whichGraphicsCardAdapter, whichOutputDevice); + } } private void InitCapture(int whichGraphicsCardAdapter, int whichOutputDevice) @@ -112,7 +115,10 @@ namespace cmonitor.server.client.reports.screen.sharpDX DesktopFrame frame = new DesktopFrame() { FullImage = Helper.EmptyArray, RegionImage = Helper.EmptyArray }; bool retrievalTimedOut = RetrieveFrame(frame, configScale); if (retrievalTimedOut) + { return null; + } + try { RetrieveFrameMetadata(frame); @@ -250,7 +256,7 @@ namespace cmonitor.server.client.reports.screen.sharpDX int sourceSubresource = frame.Width / width; if (sourceSubresource >= 1) { - while (sourceSubresource>0 && smallerTexture.Description.Width / (1 << sourceSubresource) < width) + while (sourceSubresource > 0 && smallerTexture.Description.Width / (1 << sourceSubresource) < width) { sourceSubresource--; } @@ -258,7 +264,6 @@ namespace cmonitor.server.client.reports.screen.sharpDX frame.Width = smallerTexture.Description.Width / (1 << sourceSubresource); frame.Height = smallerTexture.Description.Height / (1 << sourceSubresource); } - //Console.WriteLine($"sourceSubresource:{sourceSubresource},frame.Width:{frame.Width},frame.Height:{frame.Height},width:{width},height:{height}"); mDevice.ImmediateContext.CopySubresourceRegion(smallerTexture, sourceSubresource, new ResourceRegion { @@ -289,13 +294,9 @@ namespace cmonitor.server.client.reports.screen.sharpDX if (frame.Width - width > 50) { bmp = new Bitmap(width, height); - bmp.SetResolution(image.HorizontalResolution, image.VerticalResolution); using Graphics graphic = Graphics.FromImage(bmp); - graphic.SmoothingMode = SmoothingMode.HighQuality; - graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; - graphic.DrawImage(image, new System.Drawing.Rectangle(0, 0, image.Width, image.Height)); + graphic.DrawImage(image, new System.Drawing.Rectangle(0, 0, width, height),0,0, frame.Width, frame.Height, GraphicsUnit.Pixel); } - //Console.WriteLine($"bmp.Width:{bmp.Width},bmp.Height:{bmp.Height}"); using System.Drawing.Image image1 = bmp;