c#中WinForm使用OpencvSharp4实现简易抓边

环境: VS2019 , OpencvSharp4 4.5.5.20211231 , .NET Framework 4.8

界面设计:

图像显示用的是picturebox 控件都是windows基本控件

效果展示:

图像是自己画图画的 所以抓的效果比较好 。其他图片的话可能需要调整一下相关参数,效果可能达不到这么好

实现原理: 在图像中选择ROI,从原图上把对应ROI部分的图像扣下来,然后对扣下来的图像进行边缘处理等操作,得到边缘和拟合线,最后在原图上将边缘和拟合线画出来即可。注意,得到的边缘是相对于ROI区域的坐标,需要转化成相对于原图的坐标才行,只需加上ROI的坐标即可。

主要部分代码:

定义的ROI类 注意一下四个点的相对位置

    public class ROI
    {
        // 四个点的顺序关系
        //  1---2
        //  |   |
        //  3---4
        public OpenCvSharp.Point FirstPoint { get; set; } = new OpenCvSharp.Point(0, 0);
        public OpenCvSharp.Point SecondPoint { get; set; } = new OpenCvSharp.Point(0, 0);
        public OpenCvSharp.Point ThirdPoint { get; set; } = new OpenCvSharp.Point(0, 0);
        public OpenCvSharp.Point FourthPoint { get; set; } = new OpenCvSharp.Point(0, 0);

        public OpenCvSharp.Point2f Center
        {
            get
            {
                OpenCvSharp.Point2f center = new OpenCvSharp.Point2f();
                center.X = (float)((FirstPoint.X + SecondPoint.X + ThirdPoint.X + FourthPoint.X) / 4.0);
                center.Y = (float)((FirstPoint.Y + SecondPoint.Y + ThirdPoint.Y + FourthPoint.Y) / 4.0);
                return center;
            }
        }

        public OpenCvSharp.Size2f Size
        {
            get
            {
                return new OpenCvSharp.Size2f(Width, Height);
            }
        }
        public int XLeft
        {
            get { return FirstPoint.X; }
        }
        public int YTop
        {
            get { return FirstPoint.Y; }
        }
        public int XRight
        {
            get { return FourthPoint.X; }
        }
        public int YBottom
        {
            get { return FourthPoint.Y; }
        }

        public double Width
        {
            get { return FourthPoint.X - FirstPoint.X; }
        }
        public double Height
        {
            get { return FourthPoint.Y - FirstPoint.Y; }
        }

        public void Reset()
        {
            FirstPoint = new OpenCvSharp.Point(0, 0);
            SecondPoint = new OpenCvSharp.Point(0, 0);
            ThirdPoint = new OpenCvSharp.Point(0, 0);
            FourthPoint = new OpenCvSharp.Point(0, 0);
        }

        // 四个点全为0 则判断为空
        public bool IsNull()
        {
            bool en = true;
            en = en && FirstPoint == new OpenCvSharp.Point(0, 0);
            en = en && SecondPoint == new OpenCvSharp.Point(0, 0);
            en = en && ThirdPoint == new OpenCvSharp.Point(0, 0);
            en = en && FourthPoint == new OpenCvSharp.Point(0, 0);
            return en;
        }

        public OpenCvSharp.Point2f[] GetCoutonrs2f()
        {
            OpenCvSharp.Point2f[] coutonrs = new OpenCvSharp.Point2f[4];
            coutonrs[0] = FirstPoint;
            coutonrs[1] = SecondPoint;
            coutonrs[2] = FourthPoint;
            coutonrs[3] = ThirdPoint;
            return coutonrs;
        }

        public OpenCvSharp.Point[] GetCoutonrs()
        {
            OpenCvSharp.Point[] coutonrs = new OpenCvSharp.Point[4];
            coutonrs[0] = FirstPoint;
            coutonrs[1] = SecondPoint;
            coutonrs[2] = FourthPoint;
            coutonrs[3] = ThirdPoint;
            return coutonrs;
        }
    }

相关变量:

    public enum eDirections  // ROI移动方向
    {
        NULL = 0,
        上 = 1,
        下 = 2,
        左 = 3,
        右 = 4
    }

    //ROI大小调整方式
    public enum eResizeMode
    {
        All = 0, // 长宽一起调整
        Width = 1, // 只变宽度 即 矩形的长
        Height = 2, //  只变高度 即 矩形的宽
    }

    public class yVars
    {
        public static string OriImg; // 原图

        public static bool IsDrawEdgeOK = false;
        public static bool pbxMouseDown = false;
        public static bool IsMouseMove = false;
        public static bool IsSelectROIOK = false;
        public static bool IsMouseUp = false;

        public static int step; //ROI区域移动步长
        public static eDirections direct = eDirections.NULL;

        public static int ROINum = 1; // 操作第一个ROI还是第二个ROI
        public static bool IsSelectingROI = false;
        //
        public static bool IsSelectROI_1 = false;
        public static bool IsSelectROI_1_OK = false;

        public static bool IsSelectROI_2 = false;
        public static bool IsSelectROI_2_OK = false;

        public static ROI myROI_1 = new ROI();
        public static ROI myROI_2 = new ROI();
    }

ROI的绘制:

矩形的ROI ,我们只需要两个点就能确定一个矩形。

我们获取到的位置是鼠标相对于picturebox的位置,需要转化成相对于图像的坐标,我的 picturebox 的 sizemode 是 stretchImage ,所以按比例转化过去就行。

在 picturebox 的 mousedown 事件中 记录鼠标按下的第一个位置 为ROI的第一个点。

我把绘制ROI的过程写在 mousemove 事件里面,这样就能实现在确定第一个点后鼠标移动时ROI区域一直显示出来

        private void pbxImgShow_MouseMove(object sender, MouseEventArgs e)
        {
            if (yVars.IsSelectROI_1 == false && yVars.IsSelectROI_2 == false)
                return;
            if (yVars.pbxMouseDown == false)
                return;
            if (yVars.IsMouseUp == true)
                return;
            int mx = 0, my = 0;
            Mat mm = new Mat(yVars.OriImg);
            // 鼠标相对于picturebox的位置
            mx = Frm_Main.Instance.pbxImgShow.PointToClient(Control.MousePosition).X;
            my = Frm_Main.Instance.pbxImgShow.PointToClient(Control.MousePosition).Y;

            // 鼠标移动时 位置在 picturebox 中就画出对应的ROI形状
            if (mx < pbxImgShow.Width && my < pbxImgShow.Height)
            {
                //转成在图片上的位置
                double xx = mx * mm.Width * 1.0 / Frm_Main.Instance.pbxImgShow.Width;
                double yy = my * mm.Height * 1.0 / Frm_Main.Instance.pbxImgShow.Height;

                if (yVars.IsSelectROI_1 == true)
                {
                    yVars.myROI_1.FourthPoint = new OpenCvSharp.Point(xx, yy);
                    yVars.myROI_1.SecondPoint = new OpenCvSharp.Point(xx, yVars.myROI_1.FirstPoint.Y);
                    yVars.myROI_1.ThirdPoint = new OpenCvSharp.Point(yVars.myROI_1.FirstPoint.X, yy);

                    mm = yActions.DrawROIMat(mm, yVars.myROI_1);
                    yVars.IsSelectROI_1_OK = true;
                }
                else if (yVars.IsSelectROI_2 == true)
                {
                    yVars.myROI_2.FourthPoint = new OpenCvSharp.Point(xx, yy);
                    yVars.myROI_2.SecondPoint = new OpenCvSharp.Point(xx, yVars.myROI_2.FirstPoint.Y);
                    yVars.myROI_2.ThirdPoint = new OpenCvSharp.Point(yVars.myROI_2.FirstPoint.X, yy);
                    mm = yActions.DrawROIMat(mm, yVars.myROI_2);
                    yVars.IsSelectROI_2_OK = true;
                }
                yVars.IsMouseMove = true;
            }
            else // 释放鼠标时的点位不在picturebox中 将相关变量值清空
            {
                if (yVars.IsSelectROI_1 == true)
                {
                    yVars.myROI_1.Reset();

                    yVars.IsSelectROI_1_OK = false;
                }
                else if (yVars.IsSelectROI_2 == true)
                {
                    yVars.myROI_2.Reset();
                    yVars.IsSelectROI_2_OK = false;
                }
            }
            pbxImgShow.Image = yImgConvert.MatToBitmap(mm);
            mm.Release();
        }

在线程或者循环等过程中定义的 mat 要及时 Release 掉。

在 mouseup 事件中就绘制完成了 注意选择的第一点和第二点,分别是ROI的 FirstPoint 和 FourthPoint  ,两点的相对位置要确定好,要保证 FirstPoint 为左上角的点 FourthPoint 为右下角的点,不是的话 就对 FirstPoint 和 FourthPoint 重新赋值, FirstPoint 为两点的 x , y 最小的点 ,FourthPoint  为两点的 x , y 最大的点。

绘制完ROI后可以对其位置和大小进行相应的调整。

        public static Mat DrawROIMat(Mat src, ROI rOI, Scalar? scalar = null, int thickness = 1, LineTypes lineTypes = LineTypes.AntiAlias)
        {
            Scalar sc = scalar ?? Scalar.Red;
            Cv2.Line(src, rOI.FirstPoint, rOI.SecondPoint, sc, thickness, lineTypes);
            Cv2.Line(src, rOI.SecondPoint, rOI.FourthPoint, sc, thickness, lineTypes);
            Cv2.Line(src, rOI.FourthPoint, rOI.ThirdPoint, sc, thickness, lineTypes);
            Cv2.Line(src, rOI.ThirdPoint, rOI.FirstPoint, sc, thickness, lineTypes);
            return src;
        }

对位置进行调整: 主要思想就是对ROI的四个点的坐标相应方向进行加减即可,主要超限问题即可。

        public static void ImgROIMove(Mat src, out Mat dstImg, ref ROI rOI, eDirections eDirections, double step, int gap = 3)
        {
            dstImg = new Mat();

            switch (eDirections)
            {
                case eDirections.NULL:
                    break;
                case eDirections.上:
                    if (rOI.YTop - step <= gap)
                    {
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X, rOI.ThirdPoint.Y - rOI.YTop + gap);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X, rOI.FourthPoint.Y - rOI.YTop + gap);
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X, gap);
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X, gap);
                    }
                    else
                    {
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X, rOI.FirstPoint.Y - step);
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X, rOI.SecondPoint.Y - step);
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X, rOI.ThirdPoint.Y - step);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X, rOI.FourthPoint.Y - step);
                    }
                    break;
                case eDirections.下:
                    if (rOI.YBottom + step >= src.Height - gap)
                    {
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X, rOI.FirstPoint.Y + src.Height - rOI.YBottom - gap);
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X, rOI.SecondPoint.Y + src.Height - rOI.YBottom - gap);
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X, src.Height - gap);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X, src.Height - gap);
                    }
                    else
                    {
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X, rOI.FirstPoint.Y + step);
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X, rOI.SecondPoint.Y + step);
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X, rOI.ThirdPoint.Y + step);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X, rOI.FourthPoint.Y + step);
                    }
                    break;
                case eDirections.左:
                    if (rOI.XLeft - step <= gap)
                    {
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X - rOI.XLeft + gap, rOI.SecondPoint.Y);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X - rOI.XLeft + gap, rOI.FourthPoint.Y);
                        rOI.ThirdPoint = new OpenCvSharp.Point(gap, rOI.ThirdPoint.Y);
                        rOI.FirstPoint = new OpenCvSharp.Point(gap, rOI.FirstPoint.Y);
                    }
                    else
                    {
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X - step, rOI.FirstPoint.Y);
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X - step, rOI.SecondPoint.Y);
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X - step, rOI.ThirdPoint.Y);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X - step, rOI.FourthPoint.Y);
                    }
                    break;
                case eDirections.右:
                    if (rOI.XRight + step >= src.Width - gap)
                    {
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X + src.Width - rOI.XRight - gap, rOI.FirstPoint.Y);
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X + src.Width - rOI.XRight - gap, rOI.ThirdPoint.Y);
                        rOI.FourthPoint = new OpenCvSharp.Point(src.Width - gap, rOI.FourthPoint.Y);
                        rOI.SecondPoint = new OpenCvSharp.Point(src.Width - gap, rOI.SecondPoint.Y);
                    }
                    else
                    {
                        rOI.FirstPoint = new OpenCvSharp.Point(rOI.FirstPoint.X + step, rOI.FirstPoint.Y);
                        rOI.SecondPoint = new OpenCvSharp.Point(rOI.SecondPoint.X + step, rOI.SecondPoint.Y);
                        rOI.ThirdPoint = new OpenCvSharp.Point(rOI.ThirdPoint.X + step, rOI.ThirdPoint.Y);
                        rOI.FourthPoint = new OpenCvSharp.Point(rOI.FourthPoint.X + step, rOI.FourthPoint.Y);
                    }
                    break;
                default:
                    break;
            }
            dstImg = yActions.DrawROIMat(src, rOI);
        }

对大小进行调整: 主要思路是 ROI 大小调整前后,其中心点坐标不变,相应的长度和宽度变了。我们就可以采用 OpenCvSharp.RotatedRect 这个类,根据 中心点坐标,相应size,和倾斜角度(正矩形为0). 最后再把 RotatedRect 的四个顶点重新赋值给 ROI的四个顶点就好,注意一下点的相对位置关系。

        public static void ImgROIResize(Mat src, out Mat dstImg, ref ROI rOI, bool IsAdd, double step, eResizeMode eResizeMode)
        {
            dstImg = new Mat();
            double height = rOI.Height, width = rOI.Width;
            if (IsAdd == true)
            {
                switch (eResizeMode)
                {
                    case eResizeMode.All:
                        height = rOI.Height + step;
                        width = rOI.Width + step;
                        break;
                    case eResizeMode.Width:
                        width = rOI.Width + step;
                        break;
                    case eResizeMode.Height:
                        height = rOI.Height + step;
                        break;
                }
            }
            else
            {
                switch (eResizeMode)
                {
                    case eResizeMode.All:
                        height = rOI.Height - step;
                        width = rOI.Width - step;
                        break;
                    case eResizeMode.Width:
                        width = rOI.Width - step;
                        break;
                    case eResizeMode.Height:
                        height = rOI.Height - step;
                        break;
                }
            }

            OpenCvSharp.Size2f size = new Size2f(width, height);
            OpenCvSharp.RotatedRect rotateRect = new RotatedRect(rOI.Center, size, 0);
            Point2f[] points = rotateRect.Points();// 获得矩形四个顶点坐标
            // 大小缩放后需要判断坐标是否超限
            for (int i = 0; i < points.Length; i++)
            {
                if (points[i].X <= 0 || points[i].Y <= 0 || points[i].X >= src.Width || points[i].Y >= src.Height)
                {
                    return;
                }
            }
            rOI.FirstPoint = new OpenCvSharp.Point(points[1].X, points[1].Y);
            rOI.SecondPoint = new OpenCvSharp.Point(points[2].X, points[2].Y);
            rOI.ThirdPoint = new OpenCvSharp.Point(points[0].X, points[0].Y);
            rOI.FourthPoint = new OpenCvSharp.Point(points[3].X, points[3].Y);
            dstImg = yActions.DrawROIMat(src, rOI);
        }

绘制并调整好ROI后,从原图上将对应的ROI图像扣下来,

        public static Mat GetROIMat(Mat mm, ROI rOI)
        {
            Mat mask = Mat.Zeros(mm.Size(), MatType.CV_8UC1);
            List<List<OpenCvSharp.Point>> pp = new List<List<OpenCvSharp.Point>>() {
               rOI.GetCoutonrs().ToList()
            };
            Cv2.FillPoly(mask, pp, new Scalar(255, 255, 255));
            OpenCvSharp.Rect rect = Cv2.BoundingRect(rOI.GetCoutonrs2f());
            if (rect.X <= 0) rect.X = 1;
            if (rect.Y <= 0) rect.Y = 0;
            if (rect.X + rect.Width > mm.Width)
                rect.Width = mm.Width - rect.X - 1;
            if (rect.Y + rect.Height > mm.Height)
                rect.Height = mm.Height - rect.Y - 1;
            Mat src = new Mat(mm, rect);
            Mat maskROI = new Mat(mask, rect);
            Mat dstImg = new Mat();
            Cv2.BitwiseAnd(src, src, dstImg, maskROI);
            return dstImg;
        }

然后对每张扣下来的mat进行边缘检测 抓边拟合等操作

部分代码

            coutonrs = yVars.myROI_1.GetCoutonrs2f();
            srcROIImg = yActions.GetROIMat(src, yVars.myROI_1);
            Cv2.CvtColor(srcROIImg, grayImg, ColorConversionCodes.RGB2GRAY);
            Cv2.Blur(grayImg, grayImg, new OpenCvSharp.Size(3, 3));
            Cv2.Canny(grayImg, cannyImg, param1, param2, param3, true);
            //获得轮廓
            Cv2.FindContours(cannyImg, out contoursROI1, out hierarchly, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple, new OpenCvSharp.Point(0, 0));

            if (contoursROI1.Length == 0)
            {
                YXH._01.yMessagebox.ShowDialogCN("ROI_1未抓到边,请调整迟滞参数,或重新选择ROI区域");
                return;
            }
            // 获取轮廓后需要将点的坐标转换到原图上 此时的坐标是相对于ROI区域的坐标
            // 即每个坐标需要加上ROI区域的左上角坐标 再将转化后的坐标添加进拟合集合内
            for (int i = 0; i < contoursROI1.Length; i++)
            {
                for (int j = 0; j < contoursROI1[i].Length; j++)
                {
                    contoursROI1[i][j] += yVars.myROI_1.FirstPoint;
                    ROI_1_Points.Add(contoursROI1[i][j]);
                    AllPoints.Add(contoursROI1[i][j]);
                }
            }

操作完成后再根据想要在界面上显示的进行相应的绘制即可。

到此这篇关于c#中WinForm使用OpencvSharp4实现简易抓边的文章就介绍到这了,更多相关c# OpencvSharp4 抓边内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • C#安装OpenCvSharp4的实现步骤

    目录 一.运行环境 二.安装步骤 1.打开VS2019,创建工程 2.使用NuGet安装OpenCvSharp 3.查看 三.测试 四.参考资料: 一.运行环境 Windows下,VS2019企业版16.7 二.安装步骤 1.打开VS2019,创建工程 选择Windows窗体应用(.NET Framework),如下图所示 2.使用NuGet安装OpenCvSharp 菜单栏->工具->NuGet包管理器->管理解决方案的NuGet程序包 分别安装OpenCvSharp4.OpenCvS

  • C#借助OpenCvSharp读取摄像头并显示的实现示例

    1,首先要安装OpenCvSharp,使用cv2的函数获取设备,并将图像转换到Bitmap using OpenCvSharp; using OpenCvSharp.Extensions; void run_cap() { Mat src = new Mat(); FrameSource frame = Cv2.CreateFrameSource_Camera(0); while (f1) { frame.NextFrame(src); Bitmap bitmap = BitmapConvert

  • c#中WinForm用OpencvSharp实现ROI区域提取的示例

    已经自学OpencvSharp一段时间了(目前工作用的是C#,就学了Opencvsharp了,vs2015,opencvsharp3),收获也有一些,现在就将我在学习过程中的收获分享出来吧. 图像处理,很常见的问题,但对于大多数时候而言,我们往往不需要去处理整张图片,而是只需要处理一部分,这就涉及到了ROI(Region of interest)的提取了.我目前提取ROI的方法是采用掩膜Mask的方法.具体的思路就是:在图像操作的时候,定义一张同等大小的空的Mask,也就是全部是0,然后将我们想

  • c#中WinForm使用OpencvSharp4实现简易抓边

    环境: VS2019 , OpencvSharp4 4.5.5.20211231 , .NET Framework 4.8 界面设计: 图像显示用的是picturebox 控件都是windows基本控件 效果展示: 图像是自己画图画的 所以抓的效果比较好 .其他图片的话可能需要调整一下相关参数,效果可能达不到这么好 实现原理: 在图像中选择ROI,从原图上把对应ROI部分的图像扣下来,然后对扣下来的图像进行边缘处理等操作,得到边缘和拟合线,最后在原图上将边缘和拟合线画出来即可.注意,得到的边缘是

  • C#中winform实现自动触发鼠标、键盘事件的方法

    程序触发鼠标.键盘事件是C#程序设计中比较常见的功能,本文实例展示了C#中winform实现自动触发鼠标.键盘事件的方法,有不错的实用价值.具体如下: 要想在C#程序中触发鼠标.键盘事件就必须要调用windows函数. 一.鼠标事件的触发 1.引用windows函数mouse_event /// <summary> /// 鼠标事件 /// </summary> /// <param name="flags">事件类型</param> /

  • C#中winform使用相对路径读取文件的方法

    本文实例讲述了C#中winform使用相对路径读取文件的方法.分享给大家供大家参考.具体分析如下: 目录结构如下图所示:   方法一:由于生成的exe文件在bin\debug目录下,可以使用向上查找目录的方式获取要读取的xml文件 复制代码 代码如下: string haarXmlPath = @"../../haarcascade_frontalface_alt_tree.xml"; FileInfo file = new FileInfo(fileName); string  fu

  • C#中Winform窗体Form的关闭按钮变灰色的方法

    本文实例讲述了C#中Winform窗体Form的关闭按钮变灰色的方法,对C#程序设计有一定的借鉴价值,分享给大家供大家参考之用.具体方法如下: 主要功能代码如下: [ DllImport ( "USER32.DLL" ) ] public static extern int GetSystemMenu(int hwnd, int bRevert); [ DllImport ( "USER32.DLL" ) ] public static extern int Rem

  • C#中WinForm程序退出方法技巧总结

    本文实例总结了C#中WinForm程序退出方法技巧.分享给大家供大家参考.具体分析如下: 在c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.ExitThread(); System.Environment.Exit(0); 等他们各自的方法不一样,下面我们就来详细介绍一下. 1.this.Close();   只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退

  • C#中winform控制textbox输入只能为数字的方法

    本文实例讲述了C#中winform控制textbox输入只能为数字的方法.分享给大家供大家参考.具体实现方法如下: 添加keyPress事件,控制键盘输入只能是自然数: 复制代码 代码如下: /// <summary> /// 控制键盘输入只能是自然数 /// </summary> /// <param name="sender"></param> /// <param name="e"></para

  • C#中Winform获取文件路径的方法实例小结

    本文实例讲述了C#中Winform获取文件路径的方法.分享给大家供大家参考.具体如下: 获取文件名方法: 用System.IO.Path.GetFileName和System.IO.Path.GetFileNameWithoutExtension(无扩展名)的方法 获取文件路径方法: //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Assembly.Location; result: X:\xxx\xxx\xxx.exe //(.exe

  • vue中axios的封装问题(简易版拦截,get,post)

    第一步还是先下载axios npm install axios --save 第二步/src/utils/目录下建立一个htttp.js import axios from 'axios'; axios.defaults.timeout = 5000; axios.defaults.baseURL =''; //http request 拦截器 axios.interceptors.request.use( config => { // const token = getCookie('名称')

  • C#中winform中panel重叠无法显示问题的解决

    C#中winform中panel重叠无法显示问题: 最近开发一个项目有个需求是需要多个模式来回切换的,本来考虑使用多个窗口来实现这个功能,但是这样做浪费资源,而且工作量大,所以想到使用panel控件来解决这个问题.但是在这个过程中遇到了一个问题,就是当多个panel控件重叠在一起时会出现有些panel控件中的内容无法显示,开始还以为是我自己手误将panel控件删除了,但是在代码中调用无法显示的控件编译器编译时并没有报错.所以可以肯定没有删除控件.最后发现原来是C#winform窗体中控件的层级搞

随机推荐