编程语言
首页 > 编程语言> > C# opencv Form显示图片

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("读取图片失败", "提示");
            }

        }
    }
}

 

 

 

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

标签:mat,Form,C#,System,openFileDialog1,opencv,OpenCvSharp,using
来源: https://www.cnblogs.com/herd/p/14890812.html