Halcon的HImage转QT的QPixmap

QPixmap HImage2Pixmap(HImage* pImage)
{
    if (pImage == NULL || !pImage->IsInitialized()) return QPixmap();

    Hlong w, h; HString hType;

    //获取HImage的通道数
    HTuple hChannels = pImage->CountChannels();
    if (hChannels == 1)
    {
        //获取HImage的数据指针
        uchar* pBuf = (uchar*)pImage->GetImagePointer1(&hType, &w, &h);

        //创建QImage图片
        QImage image(w, h, QImage::Format_Indexed8);

        //memcpy
        for (int i = 0; i < h; i++, pBuf += w)
        {
            uchar *pDest = image.scanLine(i);
            memcpy(pDest, pBuf, w);
        }

        return QPixmap::fromImage(image);
    }
    else if (hChannels == 3)
    {
        //获取HImage的数据指针
        uchar* pDataR = NULL;
        uchar* p

你可能感兴趣的:(QT,Halcon,HImage,QPixmap)