Click here to Skip to main content
11,928,754 members (54,748 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked

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

, 9 Mar 2014 CPOL
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 Opulent Infotech
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

You may also be interested in...

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
professionalSOHAM_GANDHI5-May-15 19:24 
AnswerRe: problem Pin
SOHAM_GANDHI5-May-15 19:26
professionalSOHAM_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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 9 Mar 2014
Article Copyright 2014 by SOHAM_GANDHI
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid