Browse Source

添加效率更高的网络监测功能

yuzhengyang 7 years ago
parent
commit
b5a60867fc

+ 1 - 1
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -100,7 +100,7 @@
     <Compile Include="IOUtils\ImageUtils\ImageHelper.cs" />
     <Compile Include="IOUtils\ImageUtils\ImageSpliter.cs" />
     <Compile Include="IOUtils\ImageUtils\RotateImageTool.cs" />
-    <Compile Include="IOUtils\ImageUtils\ScreenCapture.cs" />
+    <Compile Include="DrawingUtils\ImageUtils\ScreenCapture.cs" />
     <Compile Include="IOUtils\ImageUtils\ThunbnailTool.cs" />
     <Compile Include="IOUtils\OfficeUtils\WordTool.cs" />
     <Compile Include="IOUtils\OfficeUtils\WordToolTester.cs" />

+ 29 - 32
Azylee.Utils/Azylee.Core/IOUtils/ImageUtils/ScreenCapture.cs

@@ -11,7 +11,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 
-namespace Azylee.Core.IOUtils.ImageUtils
+namespace Azylee.Core.DrawingUtils.ImageUtils
 {
     /// <summary>
     /// 屏幕捕获类
@@ -19,6 +19,32 @@ namespace Azylee.Core.IOUtils.ImageUtils
     public class ScreenCapture
     {
         /// <summary>
+        /// Winform 屏幕截图
+        /// </summary>
+        /// <returns></returns>
+        public static Bitmap Capture()
+        {
+            try
+            {
+                //屏幕宽
+                int iWidth = Screen.PrimaryScreen.Bounds.Width;
+                //屏幕高
+                int iHeight = Screen.PrimaryScreen.Bounds.Height;
+                //按照屏幕宽高创建位图
+                Bitmap bitmap = new Bitmap(iWidth, iHeight);
+                //从一个继承自Image类的对象中创建Graphics对象
+                Graphics gc = Graphics.FromImage(bitmap);
+                //抓屏并拷贝到myimage里
+                gc.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
+                gc.Dispose();
+                return bitmap;
+            }
+            catch { }
+            return null;
+        }
+
+        #region gdi 屏幕截图
+        /// <summary>
         /// 把当前屏幕捕获到位图对象中
         /// </summary>
         /// <param name="hdcDest">目标设备的句柄</param>
@@ -43,7 +69,6 @@ namespace Azylee.Core.IOUtils.ImageUtils
         int nYSrc,
         int dwRop
         );
-
         [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
         private static extern IntPtr CreateDC(
         string lpszDriver, // 驱动名称
@@ -51,12 +76,11 @@ namespace Azylee.Core.IOUtils.ImageUtils
         string lpszOutput, // 无用,可以设定位"NULL"
         IntPtr lpInitData // 任意的打印机数据
         );
-
         /// <summary>
         /// 屏幕捕获到位图对象中
         /// </summary>
         /// <returns></returns>
-        public static Bitmap Capture()
+        public static Bitmap CaptureDC()
         {
             try
             {
@@ -84,34 +108,6 @@ namespace Azylee.Core.IOUtils.ImageUtils
             }
             catch { return null; }
         }
-
-        /// <summary>
-        /// 压缩图片
-        /// </summary>
-        /// <param name="originalImage"></param>
-        public static Bitmap MakeThumbnail(Image originalImage, int towidth, int toheight)
-        {
-            int x = 0;
-            int y = 0;
-            int ow = originalImage.Width;
-            int oh = originalImage.Height;
-
-            //新建一个bmp图片
-            Bitmap bitmap = new Bitmap(towidth, toheight);
-            //新建一个画板
-            Graphics g = Graphics.FromImage(bitmap);
-            //设置高质量插值法
-            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
-            //设置低质量,高速度呈现平滑程度
-            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
-            //清空画布并以透明背景色填充
-            g.Clear(System.Drawing.Color.Transparent);
-
-            //在指定位置并且按指定大小绘制原图片的指定部分
-            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
-            return bitmap;
-        }
-
         [StructLayout(LayoutKind.Sequential)]
         struct CURSORINFO
         {
@@ -138,5 +134,6 @@ namespace Azylee.Core.IOUtils.ImageUtils
 
             vCursor.Draw(g, vRectangle);
         }
+        #endregion
     }
 }

+ 28 - 0
Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/NetcardInfoTool.cs

@@ -11,6 +11,7 @@ using System.Diagnostics;
 using System.Net;
 using System.Net.NetworkInformation;
 using System.Net.Sockets;
+using System.Runtime.InteropServices;
 using System.Text;
 
 namespace Azylee.Core.WindowsUtils.InfoUtils
@@ -56,6 +57,33 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
             }
         }
         /// <summary>
+        /// 获取网络连接状态
+        /// </summary>
+        /// <param name="dwFlag"></param>
+        /// <param name="dwReserved"></param>
+        /// <returns></returns>
+        [DllImport("winInet.dll")]
+        private static extern bool InternetGetConnectedState(ref int dwFlag, int dwReserved);
+        /// <summary>
+        /// 获取网络连接状态
+        /// </summary>
+        /// <returns></returns>
+        public static bool LocalConnectionStatus()
+        {
+            int INTERNET_CONNECTION_MODEM = 1;
+            int INTERNET_CONNECTION_LAN = 2;
+
+            int dwFlag = 0;
+            if (InternetGetConnectedState(ref dwFlag, 0))
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
         /// 获取网络连接操作状态
         /// </summary>
         /// <param name="mac"></param>