//halcon彩色转Qt彩色
QImage HobjectToQImage(HObject img){
HObject img;
HTuple rImage , gImage , bImage , type , hvWidth , hvHeight;
BYTE* vcPr = NULL;
BYTE* vcPg = NULL;
BYTE* vcPb = NULL;
BYTE* vcPImage = NULL;
INT32 vcWidth = 0 , vcHeight = 0;
//ReadImage(&img,"C:/Users/Administrator/Desktop/8.bmp");
GetImagePointer3(img , &rImage , &gImage , &bImage , &type , &hvWidth , &hvHeight);
vcWidth = (Hlong)hvWidth;
vcHeight = (Hlong)hvHeight;
vcPb = (BYTE*)rImage[0].L();
vcPg = (BYTE*)gImage[0].L();
vcPr = (BYTE*)bImage[0].L();
//计算bmp图片实际的宽度,因为bmp图片宽度必须四字节对齐
int bmpWidth = (vcWidth*3 + 3)/4*4;
vcPImage = new BYTE[bmpWidth * vcHeight * 3];//給bmp图片分配内存空间
//将halcon图象类型HObject中的数据拷贝出来,放到C++变量类型中
for(int i = vcHeight - 1 ; i > 0 ; i--){
for(int j = 0 ; j < vcWidth ; j++){
*(vcPImage + i*bmpWidth + j*3 + 0) = *vcPb;
*(vcPImage + i*bmpWidth + j*3 + 1) = *vcPg;
*(vcPImage + i*bmpWidth + j*3 + 2) = *vcPr;
vcPb++;
vcPg++;
vcPr++;
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载