Browse Source

add missing files: DrawFunction.cs

gsp 3 years ago
parent
commit
9852c5aff3

+ 37 - 34
OTSIncAReportApp/Control_Graph/Controls/Control_DrawDistrbutionImageAndBSE.cs

@@ -26,8 +26,34 @@ namespace OTSIncAReportGraph.Controls
 
         //防止segment过多的数量限制,先写300吧,过少也不好,过防止过多程序而卡死
         private const int m_segment_overflownumber = 400;
+        //缩放的增大缩小的增量
+        private const float m_f_zoom_increment = 0.05f;
+
+        //最大缩放倍数
+        private const float m_f_zoom_max = 4f;
+
+        //最小缩放倍数
+        private const float m_f_zoom_mix = 0.05f;
+
+      
+
+        //标尺原先大小的记录,参与计算
+        private const float m_f_old_ruler_size = 100;
+
+
+
         #region 变量定义
 
+        //缩放的基数,临时变量
+        private float m_f_widthandheight_js = 0;
+
+        //与原先缩放的记录数
+        private float m_f_zoom_record = 1;
+
+        //标尺的大小记录
+        public float m_f_ruler_size = 100;
+        //每像素代表的尺寸大小,还不知道在哪里进行计算
+        public float m_f_onepixel_size = 4.5f;
         //国际化
         Language lan;
         //国际化存储信息
@@ -102,29 +128,11 @@ namespace OTSIncAReportGraph.Controls
 
 
 
-        //缩放的增大缩小的增量
-        private float m_f_zoom_increment = 0.05f;
-
-        //缩放的基数,临时变量
-        private float m_f_widthandheight_js = 0;
-
-        //与原先缩放的记录数
-        private float m_f_zoom_record = 1;
-
-        //最大缩放倍数
-        private float m_f_zoom_max = 4f;
+    
 
-        //最小缩放倍数
-        private float m_f_zoom_mix = 0.05f;
+   
 
-        //标尺的大小记录
-        public float m_f_ruler_size = 100;
 
-        //标尺原先大小的记录,参与计算
-        private float m_f_old_ruler_size = 100;
-
-        //每像素代表的尺寸大小,还不知道在哪里进行计算
-        public float m_f_onepixel_size = 4.5f;
 
         //提供鼠标在右下角显示的文本,左侧
         private string m_str_mouseshow_left = "";
@@ -903,7 +911,7 @@ namespace OTSIncAReportGraph.Controls
                     }
 
                
-                if (dp.Rect.Left < 0 || dp.Rect.Right > this.Width || dp.Rect.Top < 0 || dp.Rect.Bottom > this.Height)
+                if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width+120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height+120)
                 {
                     dp.Operator = ParticleOperator.NODISPLAY;
                 }
@@ -1172,11 +1180,13 @@ namespace OTSIncAReportGraph.Controls
 
                         //重新计算小矩形边框
                         dp.SmallRect = dp.GetSmallRectangleFromRect();
+
+                        if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
+                        {
+                            dp.Operator = ParticleOperator.NODISPLAY;
+                        }
                     }
-                    if (dp.Rect.Left < 0 || dp.Rect.Right > this.Width || dp.Rect.Top < 0 || dp.Rect.Bottom > this.Height)
-                    {
-                        dp.Operator = ParticleOperator.NODISPLAY;
-                    }
+               
                 }
 
                 foreach (var item in m_list_dfield)
@@ -1458,20 +1468,13 @@ namespace OTSIncAReportGraph.Controls
                 CMenuStrip.Items[7].Text = table["str9"].ToString();
             }
 
-            //缩放的增大缩小的增量
-            m_f_zoom_increment = 0.05f;
+        
             //缩放的基数,临时变量
             m_f_widthandheight_js = 0;
             //与原先缩放的记录数
             m_f_zoom_record = 1;
             //最大缩放倍数
-            m_f_zoom_max = 4f;
-            //最小缩放倍数
-            m_f_zoom_mix = 0.05f;
-            //标尺的大小记录
-            m_f_ruler_size = 100;
-            //标尺原先大小的记录,参与计算
-            m_f_old_ruler_size = 100;
+        
             //每像素代表的尺寸大小,还不知道在哪里进行计算
             m_f_onepixel_size = 4.5f;
             //提供鼠标在右下角显示的文本,左侧

+ 8 - 51
OTSIncAReportApp/Control_Graph/Controls/Control_DrawDistrbutionSortImage.cs

@@ -761,43 +761,7 @@ namespace OTSIncAReportGraph.Controls
         #region 鼠标操作相关事件
         protected override void OnMouseWheel(MouseEventArgs e)
         {
-            //实现直接滚动,进行拖动,按下ctrl进行滚动,是缩放
-            //if (e.Delta > 0)
-            //{
-            //    if (m_CtrlKeyDown == false)
-            //    {
-            //        OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta));
-            //        //OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta));
-            //        OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y + 30, e.Delta));
-            //        //OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta));
-            //    }
-            //    else
-            //    {
-            //        if (m_f_zoom_record <= m_f_zoom_max)
-            //        {
-            //            //放大
-            //            ZoomIn();
-            //        }
-            //    }
-            //}
-            //else
-            //{
-            //    if (m_CtrlKeyDown == false)
-            //    {
-            //        OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta));
-            //        //OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta));
-            //        OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y - 30, e.Delta));
-            //        //OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta));
-            //    }
-            //    else
-            //    {
-            //        if (m_f_zoom_record >= m_f_zoom_mix)
-            //        {
-            //            //缩小
-            //            ZoomOut();
-            //        }
-            //    }
-            //}
+            
             if (m_CtrlKeyDown == true)
             {
                 if (e.Delta > 0)
@@ -815,7 +779,7 @@ namespace OTSIncAReportGraph.Controls
             }
             else
             {
-                //判断没有在进行多选状态时,在进行多选时,不让其拖动
+               
 
                 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
                 {
@@ -832,19 +796,16 @@ namespace OTSIncAReportGraph.Controls
                             ds.Rect.Y + e.Delta / 2,
                             ds.Rect.Width,
                             ds.Rect.Height);
-                            ds.DraggingPoint = e.Location;
+                            
+                            
                         }
-                        item.DraggingPoint = e.Location;
+                      
 
                         //获取矩形的rectangle
                         dp.Rect = dp.GetRectFromDSegment();
 
-                        //通过line获取路径边缘
-                        dp.GPath = dp.GetRegionFromDSegments();
-
-                        //重新计算小矩形边框
-                        dp.SmallRect = dp.GetSmallRectangleFromRect();
-                        if (dp.Rect.Left < 0 || dp.Rect.Right > this.Width || dp.Rect.Top < 0 || dp.Rect.Bottom > this.Height)
+                       
+                        if (dp.Rect.Left < -60 || dp.Rect.Right > this.Width +60|| dp.Rect.Top < -60 || dp.Rect.Bottom > this.Height+60)
                         {
                             dp.Operator = ParticleOperator.NODISPLAY;
                         }
@@ -867,10 +828,6 @@ namespace OTSIncAReportGraph.Controls
 
             }
 
- 
-
-      
-
             Invalidate();
         }
 
@@ -1035,7 +992,7 @@ namespace OTSIncAReportGraph.Controls
             }
 
 
-            //Invalidate();
+            Invalidate();
         }
 
         protected override void OnMouseUp(MouseEventArgs e)

+ 625 - 0
OTSIncAReportApp/FunctionClass/Common/DrawFunction.cs

@@ -0,0 +1,625 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using OTSIncAReportGraph.Class;
+using System.Runtime.InteropServices;
+using System.IO;
+using OpenCvSharp;
+
+namespace OTSIncAReportGraph.Class
+{
+    /// <summary>
+    /// 相关图表绘制函数统一封装类
+    /// </summary>
+    static class DrawFunction
+    {
+        [DllImport("gdi32.dll")]
+        public static extern System.UInt32 GetPixel(IntPtr hdc, int xPos, int yPos);
+
+        /// <summary>    
+        /// 将一个byte的数组转换为8bit灰度位图    
+        /// </summary>    
+        /// <param name="data">数组</param>    
+        /// <param name="width">图像宽度</param>    
+        /// <param name="height">图像高度</param>    
+        /// <returns>位图</returns>    
+        public static Bitmap ToGrayBitmap(byte[] data, int width, int height)
+        {
+            //// 申请目标位图的变量,并将其内存区域锁定    
+            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
+            //// BitmapData这部分内容  需要 using System.Drawing.Imaging;  
+            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height),
+            ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
+
+            //// 获取图像参数    
+            // 扫描线的宽度   
+            //int stride = bmpData.Stride;
+            // 显示宽度与扫描线宽度的间隙  
+            int offset = width - width;
+            // 获取bmpData的内存起始位置
+            IntPtr iptr = bmpData.Scan0;
+            // 用stride宽度,表示这是内存区域的大小
+            int scanBytes = width * height;
+
+            //// 下面把原始的显示大小字节数组转换为内存中实际存放的字节数组    
+            int posScan = 0, posReal = 0;// 分别设置两个位置指针,指向源数组和目标数组    
+            byte[] pixelValues = new byte[scanBytes];  //为目标数组分配内存    
+
+            for (int x = 0; x < height; x++)
+            {
+                //// 下面的循环节是模拟行扫描    
+                for (int y = 0; y < width; y++)
+                {
+                    pixelValues[posScan++] = data[posReal++];
+                }
+                posScan += offset;  //行扫描结束,要将目标位置指针移过那段“间隙”    
+            }
+            //// 用Marshal的Copy方法,将刚才得到的内存字节数组复制到BitmapData中    
+            System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, iptr, scanBytes);
+            bmp.UnlockBits(bmpData);  // 解锁内存区域    
+
+            //// 下面的代码是为了修改生成位图的索引表,从伪彩修改为灰度    
+            ColorPalette tempPalette;
+            using (Bitmap tempBmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed))
+            {
+                tempPalette = tempBmp.Palette;
+            }
+            for (int i = 0; i < 256; i++)
+            {
+                tempPalette.Entries[i] = Color.FromArgb(i, i, i);
+            }
+            bmp.Palette = tempPalette;
+
+            //// 算法到此结束,返回结果    
+            return bmp;
+        }
+
+        /// <summary>
+        /// *有BUG*将图片缩放到目标宽高,该方法有问题,不应该继续使用,图像申缩存在不规则问题
+        /// </summary>
+        /// <param name="sourceImage"></param>
+        /// <param name="targetWidth"></param>
+        /// <param name="targetHeight"></param>
+        /// <returns></returns>
+        public static Image pictureProcess(Image sourceImage, int targetWidth, int targetHeight)
+        {
+            int width;//图片最终的宽  
+            int height;//图片最终的高  
+            try
+            {
+                System.Drawing.Imaging.ImageFormat format = sourceImage.RawFormat;
+                Bitmap targetPicture = new Bitmap(targetWidth, targetHeight);
+                Graphics g = Graphics.FromImage(targetPicture);
+                g.Clear(Color.White);
+
+                //计算缩放图片的大小  
+                if (sourceImage.Width > targetWidth && sourceImage.Height <= targetHeight)
+                {
+                    width = targetWidth;
+                    height = (width * sourceImage.Height) / sourceImage.Width;
+                }
+                else if (sourceImage.Width <= targetWidth && sourceImage.Height > targetHeight)
+                {
+                    height = targetHeight;
+                    width = (height * sourceImage.Width) / sourceImage.Height;
+                }
+                else if (sourceImage.Width <= targetWidth && sourceImage.Height <= targetHeight)
+                {
+                    width = sourceImage.Width;
+                    height = sourceImage.Height;
+                }
+                else
+                {
+                    width = targetWidth;
+                    height = (width * sourceImage.Height) / sourceImage.Width;
+                    if (height > targetHeight)
+                    {
+                        height = targetHeight;
+                        width = (height * sourceImage.Width) / sourceImage.Height;
+                    }
+                }
+                g.DrawImage(sourceImage, (targetWidth - width) / 2, (targetHeight - height) / 2, width, height);
+                g.Dispose();
+                return targetPicture;
+            }
+            catch (Exception ex)
+            {
+                string str = ex.ToString();
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// 根据传入的宽和高,取得当前对应显示的4:3的标准分辨率
+        /// </summary>
+        /// <returns></returns>
+        public static Rectangle Get43ScaleResolving(int in_width, int in_height)
+        {
+            Rectangle rect_resolving = new Rectangle();
+            int width_min = 0;
+            int height_min = 0;
+            int width_max = 0;
+            int height_max = 0;
+
+            width_min = 1600;
+            height_min = 1200;
+            width_max = 2048;
+            height_max = 1536;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 1400;
+            height_min = 1050;
+            width_max = 1600;
+            height_max = 1200;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 1280;
+            height_min = 1024;
+            width_max = 1400;
+            height_max = 1050;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 1024;
+            height_min = 768;
+            width_max = 1280;
+            height_max = 1024;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 800;
+            height_min = 600;
+            width_max = 1024;
+            height_max = 768;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 640;
+            height_min = 480;
+            width_max = 800;
+            height_max = 600;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 320;
+            height_min = 240;
+            width_max = 640;
+            height_max = 480;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            width_min = 0;
+            height_min = 0;
+            width_max = 320;
+            height_max = 240;
+            if ((in_width >= width_min && in_width < width_max) || (in_height >= height_min && in_height < height_max))
+                rect_resolving = new Rectangle(0, 0, width_min, height_min);
+
+            return rect_resolving;
+        }
+
+        /// <summary>  
+        /// [该方法效果正确,但速度上慢,淘汰掉],上下翻转  
+        /// </summary>  
+        /// <param name="mybm">原始图片</param>  
+        /// <param name="width">原始图片的长度</param>  
+        /// <param name="height">原始图片的高度</param>  
+        public static Bitmap RevPicUD(Bitmap mybm, int width, int height)
+        {
+            Bitmap bm = new Bitmap(width, height);
+            int x, y, z;
+            Color pixel;
+            for (x = 0; x < width; x++)
+            {
+                for (y = height - 1, z = 0; y >= 0; y--)
+                {
+                    pixel = mybm.GetPixel(x, y);//获取当前像素的值  
+                    bm.SetPixel(x, z++, Color.FromArgb(pixel.R, pixel.G, pixel.B));//绘图  
+                }
+            }
+            return bm;
+        }
+
+
+        /// <summary>
+        /// 实现计算的方法,就是输出个数字,然后向上寻找倍数,然后返回来根
+        /// </summary>
+        /// <param name="in_number"></param>
+        /// <returns></returns>
+        public static int GetSquareRoot(int in_number)
+        {
+            int i_increase = 1;
+
+            while (true)
+            {
+                //防止死循环
+                if (i_increase > 10000)
+                    return i_increase;
+
+                int ls_i = i_increase * i_increase;
+                if (in_number > ls_i)
+                {
+                    //如果当前的数值已经大于平方数的话,那就继续下一次的平方
+                    i_increase++;
+                    continue;
+                }
+                else
+                {
+                    //如果已经小于平方数的话,那就说明已经找到了平方根,返回
+                    return i_increase;
+                }
+            }
+        }
+
+
+        /// <summary>
+        /// 根据传入的数字返回对应的颜色,范围1-17种颜色,挑出来比较谈的颜色为对比效果好看而挑选
+        /// </summary>
+        /// <param name="number"></param>
+        /// <returns></returns>
+        public static Color GetColorByNumber(int number)
+        {
+            Color ret_color = new Color();
+            switch (number)
+            {
+                case 1:
+                    ret_color = Color.Blue;
+                    break;
+                case 2:
+                    ret_color = Color.Brown;
+                    break;
+                case 3:
+                    ret_color = Color.LimeGreen;
+                    break;
+                case 13:
+                    ret_color = Color.Cyan;
+                    break;
+                case 4:
+                    ret_color = Color.DarkBlue;
+                    break;
+                case 5:
+                    ret_color = Color.Red;
+                    break;
+                case 6:
+                    ret_color = Color.SaddleBrown;
+                    break;
+                case 7:
+                    ret_color = Color.DimGray;
+                    break;
+                case 8:
+                    ret_color = Color.Navy;
+                    break;
+                case 9:
+                    ret_color = Color.Peru;
+                    break;
+                case 10:
+                    ret_color = Color.Red;
+                    break;
+                case 11:
+                    ret_color = Color.SeaGreen;
+                    break;
+                case 12:
+                    ret_color = Color.MintCream;
+                    break;
+                case 14:
+                    ret_color = Color.PaleTurquoise;
+                    break;
+                case 15:
+                    ret_color = Color.SeaShell;
+                    break;
+                case 16:
+                    ret_color = Color.Snow;
+                    break;
+                case 17:
+                    ret_color = Color.WhiteSmoke;
+                    break;
+
+                default:
+                    ret_color = Color.White;
+                    break;
+            }
+
+            return ret_color;
+        }
+
+        /// <summary>
+        /// 获取一个自绘模仿进度条的bitemap对象,传入进度的值,0-100之间
+        /// </summary>
+        /// <param name="process_value"></param>
+        /// <returns></returns>
+        public static Bitmap GetProcessBitmap(int process_value)
+        {
+            Bitmap bmp = new Bitmap(104, 30); //这里给104是为了左边和右边空出2个像素,剩余的100就是百分比的值
+            Graphics g = Graphics.FromImage(bmp);
+            g.Clear(Color.White); //背景填白色
+                                  //g.FillRectangle(Brushes.Red, 2, 2, this.Press, 26);  //普通效果
+                                  //填充渐变效果
+            SolidBrush drawBrush = new SolidBrush(Color.Black);
+            g.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(30, 2), new System.Drawing.Point(30, 30), Color.Red, Color.Gray), 2, 2, process_value, 26);
+            g.DrawString(process_value.ToString(), new Font("宋体", 9), drawBrush, 50, 8);
+            return bmp;
+        }
+
+
+
+        /// <summary>
+        /// 获取一个自绘模仿进度条的bitemap对象,传入进度的值,0-100之间[重载可以自定设置背景色]
+        /// </summary>
+        /// <param name="process_value"></param>
+        /// <param name="back_color"></param>
+        /// <returns></returns>
+        public static Bitmap GetProcessBitmap(float process_value, Color back_color)
+        {
+            if (process_value < 0)
+                process_value = 0;
+            if (process_value > 100)
+                process_value = 100;
+            Bitmap bmp = new Bitmap(104, 30); //这里给104是为了左边和右边空出2个像素,剩余的100就是百分比的值
+            Graphics g = Graphics.FromImage(bmp);
+            g.Clear(back_color); //背景填白色
+                                 //g.FillRectangle(Brushes.Red, 2, 2, this.Press, 26);  //普通效果
+                                 //填充渐变效果
+            SolidBrush drawBrush = new SolidBrush(Color.Black);
+            g.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(30, 2), new System.Drawing.Point(30, 30), Color.Red, Color.Gray), 2, 2, process_value, 26);
+            g.DrawString(process_value.ToString(), new Font("宋体", 9), drawBrush, 50, 8);
+            return bmp;
+        }
+
+
+        /// <summary>
+        /// [颜色:16进制转成RGB]
+        /// </summary>
+        /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
+        /// <returns></returns>
+        public static System.Drawing.Color colorHx16toRGB(string strHxColor)
+        {
+            try
+            {
+                if (strHxColor.Length == 0)
+                {//如果为空
+                    return System.Drawing.Color.FromArgb(0, 0, 0);//设为黑色
+                }
+                else
+                {//转换颜色
+                    if (strHxColor.IndexOf('#') > -1)
+                    {
+                        //如果颜色格式是 #0000FF 格式的
+                        return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
+                    }
+                    else
+                    {
+                        //如果颜色格式是 0000FF 格式的
+                        return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
+                    }
+                }
+            }
+            catch
+            {//设为黑色
+                return System.Drawing.Color.FromArgb(0, 0, 0);
+            }
+        }
+
+
+        /// <summary>
+        /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
+        /// </summary>
+        /// <param name="path"></param>
+        /// <returns></returns>
+        public static Bitmap ReadImageFile(string path)
+        {
+            if (!File.Exists(path))
+            {
+                return null;//文件不存在
+            }
+            FileStream fs = File.OpenRead(path); //OpenRead
+            int filelength = 0;
+            filelength = (int)fs.Length; //获得文件长度 
+            Byte[] image = new Byte[filelength]; //建立一个字节数组 
+            fs.Read(image, 0, filelength); //按字节流读取 
+            System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
+            fs.Close();
+            Bitmap bit = new Bitmap(result);
+            return bit;
+        }
+        //图片转成二进制        
+        public static byte[] GetPictureData(string imagepath)
+        {
+            /**/
+            ////根据图片文件的路径使用文件流打开,并保存为byte[]             
+            FileStream FileStream = new FileStream(imagepath, FileMode.Open);
+            byte[] byData = new byte[FileStream.Length];
+            FileStream.Read(byData, 0, byData.Length);
+            FileStream.Close();
+            return byData;
+        }
+
+
+        /// <summary>
+        /// 将image转成bytes
+        /// </summary>
+        /// <param name="in_img"></param>
+        /// <returns></returns>
+        public static byte[] ImageConvertToBytes(System.Drawing.Image in_img)
+        {
+            MemoryStream ms = new MemoryStream();
+            in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
+            return ms.ToArray();
+        }
+
+
+        /// <summary> 
+        /// Resize图片
+        /// </summary>
+        /// <param name="bmp">原始Bitmap</param>
+        /// <param name="newW">新的宽度</param>
+        /// <param name="newH">新的高度</param>
+        /// <returns>处理以后的图片</returns>
+        public static Bitmap KiResizeImage(Bitmap bmp, int newW, int newH)
+        {
+            try
+            {
+                Bitmap b = new Bitmap(newW, newH);
+                Graphics g = Graphics.FromImage(b);
+
+                // 插值算法的质量
+                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
+
+                g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
+                g.Dispose();
+
+                return b;
+            }
+            catch
+            {
+                return null;
+            }
+        }
+
+        public static Bitmap GetReZoomBitmap(Bitmap in_bp)
+        {
+            Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(in_bp);
+            Mat dst = new Mat();
+
+            Cv2.AdaptiveThreshold(src, dst, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 27, 25);
+
+            //绝对缩放,
+            Mat dst2 = new Mat();
+            int col = dst.Width;//获取原图像的大小
+            int rows = dst.Height;
+            Cv2.Resize(dst, dst2, new OpenCvSharp.Size(4 * col, 4 * rows), 0, 0, InterpolationFlags.Cubic);
+
+            return OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst2);
+        }
+
+
+    }
+
+
+    /// <summary>
+    /// 获取当前桌面显示器相关信息,暂未考虑多显示器
+    /// </summary>
+    static public class MyPrimaryScreen
+    {
+
+        #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 System.Drawing.Size WorkingArea
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                System.Drawing.Size size = new System.Drawing.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 System.Drawing.Size DESKTOP
+        {
+            get
+            {
+                IntPtr hdc = GetDC(IntPtr.Zero);
+                System.Drawing.Size size = new System.Drawing.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
+
+    }
+}