using namespace cv;
Mat src, src_gray;
CvRect Rect;
// 開啟檔案對話框
if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK){
// 讀取影像
src = imread( msclr::interop::marshal_as< std::string >(openFileDialog1->FileName), CV_LOAD_IMAGE_COLOR);
System::Drawing::Graphics^ graphics = pictureBox1->CreateGraphics();
System::IntPtr ptr(src.ptr()); // 傳入指標
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(src.cols,src.rows,src.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
//pictureBox1->Width = src.cols;
//pictureBox1->Height = src.rows;
System::Drawing::RectangleF rect(0,0,pictureBox1->Width,pictureBox1->Height);
graphics->DrawImage(b,rect);
範例程式: ShowOpenCVImage245
留言列表