cv::mat与Bitmap的相互转化

转自:https://blog.csdn.net/u012156872/article/details/103675369

Gdiplus::Bitmap* MatToCGdiImage(Mat& mat)
{
	cv::cuda::GpuMat matg;
	if (mat.empty())
		return NULL;
 
	//检查图像位深
	if (mat.depth() != CV_8U)
	{
		return NULL;
	}
 
	//cv::Mat newMat;
	if (mat.channels() == 1)
		cv::cvtColor(mat, mat, CV_GRAY2BGRA);
	else if (mat.channels() == 3)
		cv::cvtColor(mat, mat, CV_BGR2BGRA);
	else
		mat = mat;
	//Gdiplus::Bitmap src(newMat.cols, newMat.rows, newMat.step1(), PixelFormat32bppARGB, newMat.data);
	//return src.Clone(0, 0, src.GetWidth(), src.GetHeight(), PixelFormat32bppARGB);
	//Gdiplus::Bitmap* image = src.Clone(0, 0, src.GetWidth(), src.GetHeight(), PixelFormat32bppARGB);
	Gdiplus::Bitmap* image = new Gdiplus::Bitmap(mat.cols, mat.rows, mat.step1(), PixelFormat32bppARGB, mat.data);
	return image;
}

 

GDI在窗体上画出bitmap

转自:https://blog.csdn.net/aoshilang2249/article/details/38359387

Graphics* g

g->DrawImage(image, rectf, 0, 0, 384, 288, UnitPixel);

你可能感兴趣的:(gdi,opencv)