QImage::QImage(uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction = Q_NULLPTR, void *cleanupInfo = Q_NULLPTR)
该文档描述了该数据,由参数 '数据' refered,必须是32位对齐的。 http://doc.qt.io/qt-5/qimage.html#QImage-3但至少不清楚究竟是什么意思。我假设,每个像素需要32位。但事实并非如此。构建像这样的图像正在工作:
uint8_t* rgb = new uint8_t[3 * height * width];
QImage Img(rgb, width, height, QImage::Format_RGB888);
但是,这是令人困惑的。当我想从图像中的像素值,我想我需要做到这一点(因为数据是32位对齐和Qrgb是32位):
QRgb*rawPixelData = (QRgb*) Img.bits();
for(uint32_t i = 0; i < (Img.width * Img.height); ++i)
{
qDebug() << "Red" << qRed(rawPixelData[i]);
qDebug() << "Green" << qGreen(rawPixelData[i]);
qDebug() << "Blue" << qBlue(rawPixelData[i]);
}
但这不工作(导致崩溃)。所以,我认为,数据不是32位对齐。那么,不是32位数据对齐,还是我理解错了什么?