Browse Source

整合通信,增加图像压缩

yuzhengyang 5 years ago
parent
commit
10422bb07c

+ 2 - 0
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -32,6 +32,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.configuration" />
     <Reference Include="System.Core" />
@@ -157,6 +158,7 @@
     <Compile Include="WindowsUtils\APIUtils\ApplicationAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\ExplorerAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\PermissionAPI.cs" />
+    <Compile Include="WindowsUtils\APIUtils\ScreenAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\SystemSleepAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\WallpaperUtils\WallpaperTool.cs" />
     <Compile Include="WindowsUtils\APIUtils\WindowsAPI.cs" />

+ 2 - 2
Azylee.Utils/Azylee.Core/DrawingUtils/ImageUtils/Img.cs

@@ -53,7 +53,7 @@ namespace Azylee.Core.DrawingUtils.ImageUtils
         /// <param name="quality">0-100</param>
         /// <param name="format"></param>
         /// <returns></returns>
-        public static byte[] Compression(Bitmap bitmap, int quality)
+        public static byte[] CompressionToByte(Image image, int quality)
         {
             try
             {
@@ -74,7 +74,7 @@ namespace Azylee.Core.DrawingUtils.ImageUtils
                     myEncoderParameters.Param[0] = myEncoderParameter;
                     using (MemoryStream ms = new MemoryStream())
                     {
-                        bitmap.Save(ms, CodecInfo, myEncoderParameters);
+                        image.Save(ms, CodecInfo, myEncoderParameters);
                         myEncoderParameters.Dispose();
                         myEncoderParameter.Dispose();
                         return ms.ToArray();

+ 7 - 6
Azylee.Utils/Azylee.Core/DrawingUtils/ImageUtils/ScreenCapture.cs

@@ -2,13 +2,16 @@
 //      https://github.com/yuzhengyang
 //      author:yuzhengyang
 //############################################################
+using Azylee.Core.WindowsUtils.APIUtils;
 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;
 using System.Windows.Forms;
 
 namespace Azylee.Core.DrawingUtils.ImageUtils
@@ -26,16 +29,14 @@ namespace Azylee.Core.DrawingUtils.ImageUtils
         {
             try
             {
-                //屏幕宽
-                int iWidth = Screen.PrimaryScreen.Bounds.Width;
-                //屏幕高
-                int iHeight = Screen.PrimaryScreen.Bounds.Height;
+                //获取屏幕分辨率
+                Size size = ScreenAPI.DESKTOP;
                 //按照屏幕宽高创建位图
-                Bitmap bitmap = new Bitmap(iWidth, iHeight);
+                Bitmap bitmap = new Bitmap(size.Width, size.Height);
                 //从一个继承自Image类的对象中创建Graphics对象
                 Graphics gc = Graphics.FromImage(bitmap);
                 //抓屏并拷贝到myimage里
-                gc.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
+                gc.CopyFromScreen(new Point(0, 0), new Point(0, 0), size);
                 gc.Dispose();
                 return bitmap;
             }

+ 123 - 0
Azylee.Utils/Azylee.Core/WindowsUtils/APIUtils/ScreenAPI.cs

@@ -0,0 +1,123 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Azylee.Core.WindowsUtils.APIUtils
+{
+    /// <summary>
+    /// 屏幕分辨率接口
+    /// </summary>
+    public class ScreenAPI
+    {
+        #region Win32 API
+        [DllImport("user32.dll")]
+        static extern IntPtr GetDC(IntPtr ptr);
+        [DllImport("gdi32.dll")]
+        static extern int GetDeviceCaps(
+        IntPtr hdc, // handle to DC
+        int nIndex // index of capability
+        );
+        [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
+        static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
+        #endregion
+        #region DeviceCaps常量
+        const int HORZRES = 8;
+        const int VERTRES = 10;
+        const int LOGPIXELSX = 88;
+        const int LOGPIXELSY = 90;
+        const int DESKTOPVERTRES = 117;
+        const int DESKTOPHORZRES = 118;
+        #endregion
+
+        #region 属性
+        /// <summary>
+        /// 获取屏幕分辨率当前物理大小
+        /// </summary>
+        public static Size WorkingArea
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                Size size = new Size();
+                size.Width = GetDeviceCaps(hdc, HORZRES);
+                size.Height = GetDeviceCaps(hdc, VERTRES);
+                ReleaseDC(IntPtr.Zero, hdc);
+                return size;
+            }
+        }
+        /// <summary>
+        /// 当前系统DPI_X 大小 一般为96
+        /// </summary>
+        public static int DpiX
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
+                ReleaseDC(IntPtr.Zero, hdc);
+                return DpiX;
+            }
+        }
+        /// <summary>
+        /// 当前系统DPI_Y 大小 一般为96
+        /// </summary>
+        public static int DpiY
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
+                ReleaseDC(IntPtr.Zero, hdc);
+                return DpiX;
+            }
+        }
+        /// <summary>
+        /// 获取真实设置的桌面分辨率大小
+        /// </summary>
+        public static Size DESKTOP
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                Size size = new Size();
+                size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
+                size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
+                ReleaseDC(IntPtr.Zero, hdc);
+                return size;
+            }
+        }
+
+        /// <summary>
+        /// 获取宽度缩放百分比
+        /// </summary>
+        public static float ScaleX
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
+                int d = GetDeviceCaps(hdc, HORZRES);
+                float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
+                ReleaseDC(IntPtr.Zero, hdc);
+                return ScaleX;
+            }
+        }
+        /// <summary>
+        /// 获取高度缩放百分比
+        /// </summary>
+        public static float ScaleY
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
+                ReleaseDC(IntPtr.Zero, hdc);
+                return ScaleY;
+            }
+        }
+        #endregion
+    }
+}

+ 0 - 1
Azylee.Utils/Azylee.YeahWeb/Azylee.YeahWeb.csproj

@@ -72,7 +72,6 @@
     <Compile Include="SocketUtils\TcpUtils\TcpDataConverter.cs" />
     <Compile Include="SocketUtils\TcpUtils\TcpDataModel.cs" />
     <Compile Include="SocketUtils\TcpUtils\TcppServer.cs" />
-    <Compile Include="SocketUtils\TcpUtils\TcpDelegate.cs" />
     <Compile Include="SocketUtils\TcpUtils\TcpStreamHelper.cs" />
     <Compile Include="ExtWebAPI\TencentWebAPI\PictureAI\PictureScener.cs" />
   </ItemGroup>

+ 12 - 1
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpClientInfo.cs

@@ -6,6 +6,9 @@ using System.Text;
 
 namespace Azylee.YeahWeb.SocketUtils.TcpUtils
 {
+    /// <summary>
+    /// 客户端信息
+    /// </summary>
     public class TcpClientInfo
     {
         /// <summary>
@@ -27,7 +30,15 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
         /// <summary>
         /// 连接密钥
         /// </summary>
-        public string  ConnectKey { get; set; }
+        public string ConnectKey { get; set; }
+        /// <summary>
+        /// 用户邮箱
+        /// </summary>
+        public string UserEmail { get; set; }
+        /// <summary>
+        /// 用户名称
+        /// </summary>
+        public string UserName { get; set; }
         /// <summary>
         /// 上行流量总计
         /// </summary>

+ 33 - 0
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpClientManager.cs

@@ -7,6 +7,9 @@ using System.Text;
 
 namespace Azylee.YeahWeb.SocketUtils.TcpUtils
 {
+    /// <summary>
+    /// 客户端信息管理器
+    /// </summary>
     public class TcpClientManager
     {
         private int HostNumber { get; set; }
@@ -135,6 +138,36 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
             }
             return false;
         }
+        public bool UpdateUserEmail(string host, string s)
+        {
+            if (IsExistByHost(host))
+            {
+                for (var i = 0; i < TcpClientList.Count; i++)
+                {
+                    if (TcpClientList[i].Host == host)
+                    {
+                        TcpClientList[i].UserEmail = s;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+        public bool UpdateUserName(string host, string s)
+        {
+            if (IsExistByHost(host))
+            {
+                for (var i = 0; i < TcpClientList.Count; i++)
+                {
+                    if (TcpClientList[i].Host == host)
+                    {
+                        TcpClientList[i].UserName = s;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
         public bool UpdateUploadFlowCount(string host, long flow)
         {
             if (IsExistByHost(host))

+ 0 - 31
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpDelegate.cs

@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Azylee.YeahWeb.SocketUtils.TcpUtils
-{
-    /// <summary>
-    /// Tcp 工具 委托声明
-    /// </summary>
-    [Obsolete]
-    public class TcpDelegate
-    {
-        /// <summary>
-        /// 接受消息委托
-        /// </summary>
-        /// <param name="host"></param>
-        /// <param name="model"></param>
-        public delegate void ReceiveMessage(string host, TcpDataModel model);
-        /// <summary>
-        /// Tcp 连接消息委托
-        /// </summary>
-        /// <param name="host"></param>
-        public delegate void OnConnect(string host);
-        /// <summary>
-        /// Tcp 断开连接消息委托
-        /// </summary>
-        /// <param name="host"></param>
-        public delegate void OnDisconnect(string host);
-    }
-}