I would follow JPN's suggestion, but using QImage::scanLine() like this:
for (int y = 0;y<height; y++)
memcpy(image.scanLine(y), rawData + y*width, width);
QImage image(width, height, QImage::Format_Indexed8);
for (int y = 0;y<height; y++)
memcpy(image.scanLine(y), rawData + y*width, width);
To copy to clipboard, switch view to plain text mode
The problem with QImage::bits() is that Qt might add padding to each row to align the rows to 32 bits.
Then you need to set the Color table like this:
QVector<QRgb> colorTable(256);
for(int i=0;i<256;i++)
colorTable[i] = qRgb(i,i,i);
image.setColorTable(colorTable);
QVector<QRgb> colorTable(256);
for(int i=0;i<256;i++)
colorTable[i] = qRgb(i,i,i);
image.setColorTable(colorTable);
To copy to clipboard, switch view to plain text mode
Bookmarks