C# opencv Form顯示圖片
阿新 • • 發佈:2021-06-16
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("讀取圖片失敗", "提示"); } } } }
########################