Click here to Skip to main content
Click here to Skip to main content

How to Display Image In Picturebox in VC++ from Iplimage and Mat

, 9 Mar 2014
Rate this:
Please Sign up or sign in to vote.
How to convert iplimage and Mat to Picture Box in VC++


This tip/trick will be useful to OpenCV programmers, who wish to use Windows Form application under Visual C++. This tip helps programmers to use Windows function with OpenCV library. The following tip shows how to assign iplimage and mat variable to picturebox image.

Assign Iplimage to Picturebox Image

In this part, it shows how to assign iplimage to picturebox image. First of all, declare the frame pointer. Iplimage type.

Declare Iplimage variable:

IplImage* frame; 

Here, create new Bitmap image from frame properties like width, height, widthstep. Set image data from frame imagedata.

Process the PictureBox.

pictureBox1->Image  = gcnew System::Drawing::Bitmap
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);

Assign Mat to Picturebox Image

In this part, it shows how to assign Mat to picturebox image. First of all, declare the frameDetected variable, Mat type.

Declare Mat variable.

Mat frameDetected; 

Here, create graphics of picturebox. Then, create new Bitmap image from frameDetected properties like cols, rows, step. Then create Rectangle with x and y with 0 value and width and height with picturebox height, width respectively. Then rectangle assign to previous initialized graphics object.

Process the PictureBox:

System::Drawing::Graphics^ graphics2 = pictureBox3->CreateGraphics();
System::IntPtr ptr2(frameDetected.ptr());
System::Drawing::Bitmap^ b2  = gcnew System::Drawing::Bitmap(frameDetected.cols,
System::Drawing::RectangleF rect2(0,0, pictureBox3->Width,pictureBox3->Height);

Points of Interest

  • Learn how to assign iplimage to picturebox image
  • Learn how to assign Mat to picturebox image




Sorry for my English. If you notice errors or can suggest a more correct version, please let me know.


  • 9 March 2014 - First release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Software Developer
India India
I am Soham Gandhi from India. I studied BE in Information Technology at University of Pune. ( I have been learning OpenCV, Enjoying it.
My research interest in Image Processing, Artificial Intelligence, Security Systems, Security Metrics. I work on OpenCV, EmguCV, Visual Studio 2008/10, Java platform.
Home Page (Blog)
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

Generalgreat PinmemberCHARLIE9126-May-14 19:37 
Questionit doesn't work for me PinmemberSoheil Hasankhani1-Apr-14 3:08 
AnswerRe: it doesn't work for me PinmemberSOHAM GANDHI1-Apr-14 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 9 Mar 2014
Article Copyright 2014 by SOHAM_GANDHI
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid