Ask Your Question

Revision history [back]

After a day or two struggling to get an OpenCV Mat to Windows Bitmap I came across a simple solution after trying so many different things found on the Net. Try this:

Mat matImage = imread("image.bmp", CV_LOAD_IMAGE_COLOR); cvtColor(matImage, matImage, CV_BGRA2RGBA);

mhBitmap = CreateBitmap(matImage.cols, matImage.rows, 1, 32, matImage.data);

And then you have a Bitmap to use in the Picture Control/Box. This is for MFC but I think it should be similar for C++/CLI. It was an ah-ha moment.

After a day or two struggling to get an OpenCV Mat to Windows Bitmap I came across a simple solution after trying so many different things found on the Net. Try this:

Mat matImage = imread("image.bmp", CV_LOAD_IMAGE_COLOR); cvtColor(matImage, matImage, CV_BGRA2RGBA);

mhBitmap = CreateBitmap(matImage.cols, matImage.rows, 1, 32, matImage.data);

And then you have a Bitmap to use in the Picture Control/Box. This is for MFC but I think it should be similar for C++/CLI. It was an ah-ha moment.

After a day or two struggling to get an OpenCV Mat to Windows Bitmap I came across a simple solution after trying so many different things found on the Net. Try this:

Mat matImage = imread("image.bmp", CV_LOAD_IMAGE_COLOR); cvtColor(matImage, matImage, CV_BGRA2RGBA);

mhBitmap hBitmap = CreateBitmap(matImage.cols, matImage.rows, 1, 32, matImage.data);

And then you have a Bitmap to use in the Picture Control/Box. This is for MFC but I think it should be similar for C++/CLI. It was an ah-ha moment.

After a day or two struggling to get an OpenCV Mat to Windows Bitmap I came across a simple solution after trying so many different things found on the Net. Try this:

Mat matImage = imread("image.bmp", CV_LOAD_IMAGE_COLOR);
cvtColor(matImage, matImage, CV_BGRA2RGBA);

CV_BGRA2RGBA);

hBitmap = CreateBitmap(matImage.cols, matImage.rows, 1, 32, matImage.data);

matImage.data);

And then you have a Bitmap to use in the Picture Control/Box. This is for MFC but I think it should be similar for C++/CLI. It was an ah-ha moment.