QPixmap::fromImage() 在 QX11PixmapData 中给出分段错误
我编写了一些代码,看起来或多或少像这样:
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 Bug?
如果这很重要的话,我正在运行 CentOS 5.5。
谢谢!
I have written some code that looks more or less like this:
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));
so lutData (unsigned char) is my indexes into the colorTable. This crashes on the last line of the snippet, and the actual line is in a library I cant see source to called QX11PixmapData. What am I doing wrong to cause this crash, or is it a Qt Bug?
I am running CentOS 5.5 if that matters.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您调用的 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 位对齐。所以你可以这样称呼它:
因为对于索引彩色图像,扫描线字节与宽度相同。
The QImage constructor you called is:
QImage::QImage ( const uchar * data, int width, int height, Format format )
Which requires the scanline data to be 32-bit aligned. So make sure it is and also has enough bytes in it. Or you can use:
QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )
Which allows specification of bytes per scanline without being 32-bit aligned. So you can call it this way:
Since for a index color image, the scanline bytes is the same as the width.