title: How to display a binary image in pictureBox VC++
body: <p>i'm working on a VC++ and OpenCV application, i'm loading images into picturBox and make some OpenCV operations on them, i assign the loaded image into IplImage to make processing on it but then assign the processed image again into the picture box, i write this code to load the image selected from openFileDialog into IplImage ,binarize the image then reassign the binarized image back to the pictureBox
  code:</p>
  
  <pre><code>const char* fileName = (const char*)(void*)
     Marshal::StringToHGlobalAnsi(openFileDialog1-&gt;FileName);
               IplImage *img=cvLoadImage(fileName,CV_LOAD_IMAGE_COLOR);
               int width=img-&gt;width;
               int height=img-&gt;height;
               IplImage *grayScaledImage=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
               cvCvtColor(img,grayScaledImage,CV_RGB2GRAY);
  cvThreshold(grayScaledImage,grayScaledImage,128,256,CV_THRESH_BINARY);
  this-&gt;pictureBox1-&gt;Image=(gcnew 
  System::Drawing::Bitmap(grayScaledImage-&gt;width,grayScaledImage-&gt;height,grayScaledImage-&gt;widthStep, 
  System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)grayScaledImage-&gt;imageData));
  </code></pre>
  
  <p>but i doesn't find a format which displays a binary image, any help about that.</p>
  
  <p>Original Image:
  <img src="https://i.stack.imgur.com/sBn3h.png" alt="enter image description here"></p>
  
  <p>Converted image:
  <img src="https://i.stack.imgur.com/nreK8.png" alt="enter image description here"></p>