Click here to Skip to main content
15,113,692 members
Articles / OpenCV
Posted 9 Mar 2014


11 bookmarked

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
9 Mar 2014CPOL1 min read
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)

You Tube Channel

Comments and Discussions

QuestionWhy IplImage ? Pin
azty6-May-15 8:09
Memberazty6-May-15 8:09 
Questionproblem Pin
Member 116666625-May-15 8:50
MemberMember 116666625-May-15 8:50 
AnswerRe: problem Pin
SOHAM_GANDHI5-May-15 19:24
MemberSOHAM_GANDHI5-May-15 19:24 
AnswerRe: problem Pin
SOHAM_GANDHI5-May-15 19:26
MemberSOHAM_GANDHI5-May-15 19:26 
GeneralRe: problem Pin
Member 116666627-May-15 8:57
MemberMember 116666627-May-15 8:57 
Generalgreat Pin
CHARLIE9126-May-14 20:37
MemberCHARLIE9126-May-14 20:37 
Questionit doesn't work for me Pin
Soheil Hasankhani1-Apr-14 4:08
MemberSoheil Hasankhani1-Apr-14 4:08 
AnswerRe: it doesn't work for me Pin
SOHAM_GANDHI1-Apr-14 5:43
MemberSOHAM_GANDHI1-Apr-14 5:43 

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

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