2

我正在尝试通过 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 raster,但它仍然给我一个失真的图像。

此外,添加了 bpp 变量,因为在 SSH 上chipDataLength 为 4*imwidth,在 VNC 上为 2*imwidth。为什么这不一样?我该怎么做才能使这段代码双向工作?

4

0 回答 0