C# opencv Form显示图片

C# opencv Form显示图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



using OpenCvSharp;
using OpenCvSharp.Extensions;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void selectButton_Click(object sender, EventArgs e)
        {
            string imgName = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "图片(*.jpg/*.png/*.gif/*.bmp)|*.jpg;*.png;*.gif;*.bmp";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                imgName = openFileDialog1.FileName;
                Mat mat = new Mat(imgName, ImreadModes.Unchanged);
                // mat 转 bitmap
                Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat); 
                pictureBox1.Image = bitmap;
            }
            else
            {
                MessageBox.Show("读取图片失败", "提示");
            }

        }
    }
}

 

 

 

########################

posted @ 2021-06-16 19:50  西北逍遥  阅读(695)  评论(0编辑  收藏  举报