通过VNC和SSH在QT4应用程序中显示图像

| 我正在尝试通过VNC运行我的QT应用程序,并且看到了一些差异。 我的图像已加载到QImage项中,并且是RGB图像。我只想处理灰度图像,因此尝试创建一个灰度图像,如下所示:
    QRgb col;
     int gray;
     for (int i = 0; i < imwidth; ++i)
     {
           for (int j = 0; j < imheight; ++j)
           {
                col = chip.pixel(i, j);
                gray = qGray(col);
                chip.setPixel(i, j, qRgb(gray, gray, gray));
            }
     }
哪里是我的QImage 然后,为了获得芯片的原始数据,我使用以下代码:
 int chipDataLength = chip.bytesPerLine();

     qDebug(\"Chip Width: %i\", imwidth);
     qDebug(\"Chip height: %i\", imheight);
     qDebug(\"Bytes per line : %i\",chipDataLength);
     int bpp = chipDataLength/imwidth;

     qDebug(\"Size uchar: %i\", sizeof(unsigned char) );
     qDebug(\"Size of qRgb: %i\", sizeof(qRgb(1,1,1)));
     unsigned char * tempData = (unsigned char *)malloc(imheight*chipDataLength*sizeof(unsigned char));

     unsigned char * oneBandData = (unsigned char *)malloc(imheight*imwidth*sizeof(unsigned char));

     tempData = chip.bits();

     for (int i = 0; i < imheight; i++)
     {
           for (int j = 0; j < imwidth; j++)
           {
               oneBandData[i*imwidth+j] = tempData[i*chipDataLength + j*bpp];
           }
     }
当我通过SSH连接(或只是坐在服务器上)运行此代码时,代码可以正常工作,并且oneBandData中具有预期的值。当我尝试通过VNC运行它时,oneBandData不正确! 我试图使用-qgraphicssystem栅格选项,但是它仍然给我失真的图像。 另外,还添加了该bpp变量,因为chipDataLength在SSH上的大小为4 *,在VNC上的大小为2 *。为什么有什么不同?如何使此代码双向运行?     
已邀请:

要回复问题请先登录注册