0

I'm trying to display a cv::Mat object (opencv) in Winform PictureBox:

void Show(cv::Mat& picture, PictureBox^ box) {
    cv::Mat pic;
    cv::resize(picture, pic, cv::Size(250, 250)); //picturebox size = 250, 250
    box->Image = gcnew System::Drawing::Bitmap(
        pic.cols, pic.rows, pic.step,
        System::Drawing::Imaging::PixelFormat::Format24bppRgb,
        (System::IntPtr)pic.data
    );
    box->Refresh();
}

The constructor of Bitmap throw exception: "Parameter is not valid". I found a similar problem from: C# "Parameter is not valid." creating new bitmap It is answered that the Bitmap is comsuming too much space. However my Bitmap is only 250x250 or ~180kB of memory. I don't think 180kB is too much.

I tried reducing the picture size to 200x200 and it works. But that is too small for my need. And this proves that the problem must be the size of picture.

Andrew
  • 26,706
  • 9
  • 85
  • 101
namcao00
  • 272
  • 1
  • 6
  • 10

0 Answers0