我需要使用openFileDialog以Mat格式读取图像并将其显示在pictureBox中(在Visual C / Visual Studio 2010中).
我搜索了很多但找不到答案.
我正在使用此代码:
openFileDialog1->Filter = "JPEG files (*.jpg)|*.jpg|Bitmap files (*.bmp)|*.bmp";
if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
Mat img;
img = imread(openFileDialog1->FileName, CV_LOAD_IMAGE_COLOR);
pictureBox1->Image = (gcnew Bitmap(img.size().width,
img.size().height,
img.widthStep,
Imaging::PixelFormat::Format24bppRgb,
(IntPtr)img.data));
}
最佳答案 这个问题已经回答了
here:
根据您的要求,您可以这样做:
Mat img;
img = imread(openFileDialog1->FileName, CV_LOAD_IMAGE_COLOR);
System::Drawing::Graphics^ graphics = pictureBox1->CreateGraphics();
System::IntPtr ptr(img.ptr());
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(img.cols,img.rows,img.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
System::Drawing::RectangleF rect(0,0,pictureBox1->Width,pictureBox1->Height);
graphics->DrawImage(b,rect);