C# opencv Form显示图片
Posted 西北逍遥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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("读取图片失败", "提示"); } } } }
########################
以上是关于C# opencv Form显示图片的主要内容,如果未能解决你的问题,请参考以下文章
OpenCV读取图片判断读取是否成功显示图片的代码(C++代码和Python代码)