0

我写了一些看起来或多或少像这样的代码:

QVector<QRgb> colorTable(256);
 QImage *qi = new QImage(lutData, imwidth,imheight, QImage::Format_Indexed8);

 while (index < 256)
 {
         colorTable.replace(index, qRgb(2552,255, 255));
         index++;
 }
 qi->setColorTable(colorTable);


 QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));

所以 lutData (unsigned char) 是我在 colorTable 中的索引。这在代码段的最后一行崩溃,实际行在一个库中,我看不到名为 QX11PixmapData 的源。我做错了什么导致这次崩溃,还是 Qt 错误?

如果这很重要,我正在运行 CentOS 5.5。

谢谢!

4

1 回答 1

3

您调用的 QImage 构造函数是:

QImage::QImage ( const uchar * data, int width, int height, Format format )

这要求扫描线数据是 32 位对齐的。因此,请确保它是并且其中有足够的字节。或者您可以使用:

QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

它允许指定每条扫描线的字节数,而不需要 32 位对齐。所以你可以这样称呼它:

QImage *qi = new QImage(lutData, imwidth, imheight, imwidth, QImage::Format_Indexed8);

由于对于索引彩色图像,扫描线字节与宽度相同。

于 2011-04-01T17:27:02.903 回答