nuanbing222:非常感谢,我试了一下,好像也不行,我是这样写的:
QImage* image = new QImage(768, 576, QImage::Format_RGB888);
memcpy(image->bits(), (uchar*)pLinearAddr, 768*576 ..
(2014-09-24 14:56)
你可以试试memcpy是不是真的从pLinearAddr处将数据拷贝至image的bits中了,我觉得很可能是因为pLinearAddr处的图像数据不是按照每个像素BGR三字节的顺序排列的。你可以试试这么写:
QImage* image = new QImage(768, 576, QImage::Format_RGB888);
int bytePerLine = image->bytesPerLine();
int imageWidth = image->width();
int imageHeight = image->height();
unsigned char* imageData = image->bits();
for (int i=0;i<imageHeight;i++)
{
for (int j=0;j<imageWidth;j++)
{
// 这里赋值时最好先确定pLinearAddr处的数据长度是imageHeight*imageWidth*3
// 也不排除它的图像数据长度与QImage\Bmp位图相同,每行都需要向4字节对齐,那就得改成pLinearAddr[i*bytePerLine + j*3 + k]了
// 这里假设你的pLinearAddr数据是按照Blue\Green\Red的顺序排列每个像素灰度的
imageData[i*bytePerLine + j*3 + 0] = pLinearAddr[i*imageWidth*3 + j*3 + 0];
imageData[i*bytePerLine + j*3 + 1] = pLinearAddr[i*imageWidth*3 + j*3 + 1];
imageData[i*bytePerLine + j*3 + 2] = pLinearAddr[i*imageWidth*3 + j*3 + 2];
}
}
之所以用for循环不用memcpy是因为现在还不能确定你的pLinearAddr数据排布与QImage的要求一致,这样写可以通过单步调试的方法知道pLinearAddr的数据排布。