Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Showing Mat image in Picturebox

Hi guys,

I'm attempting to create a GUI for my project and I am having issues displaying the output in the GUI picturebox. I used the following function I found online to convert the Mat image to bitmap:

void DrawCVImage(System::Windows::Forms::Control^ control, cv::Mat& colorImage)
{
    System::Drawing::Graphics^ graphics = control->CreateGraphics();
    System::IntPtr ptr(colorImage.ptr());
    System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(colorImage.cols, colorImage.rows, colorImage.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
    System::Drawing::RectangleF rect(0, 0, control->Width, control->Height);
    graphics->DrawImage(b, rect);
}

I then just did a simple:

                frame = imread("C:\\Users\\xxx\\Pictures\\picture.jpg");
                DrawCVImage(pictureBox1,frame);

but only a tiny bit of the picture appears as shown here: http://i.imgur.com/KKviOOv.jpg

Thanks in advance!