彩色图像:
//截取电脑屏幕图像
QPixmap pixMap = QPixmap::grabWindow(QApplication::desktop()->winId());
pixMap.save("D:/A.png", "png");
HalconCpp::HObject ho_ImageR, ho_ImageG, ho_ImageB;
QImage qimg = pixMap.toImage();
int width = qimg.width();
int height = qimg.height();
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
unsigned char* pDataR = nullptr, *pDataG = nullptr, *pDataB = nullptr;
pDataR = (unsigned char*)malloc(width*height * sizeof(unsigned char));
pDataG = (unsigned char*)malloc(width*height * sizeof(unsigned char));
pDataB = (unsigned char*)malloc(width*height * sizeof(unsigned char));
memset(pDataR, 0, width * height * sizeof(unsigned char));
memset(pDataG, 0, width * height * sizeof(unsigned char));
memset(pDataB, 0, width * height * sizeof(unsigned char));
for (size_t i = 0; i < height; i++)
{
uchar* pScr = qimg.scanLine(i);
for (size_t j = 0; j < width; j++)