If the data is an array of ints (i.e. 4 byte numbers) then there's no better way I am aware of.
If the array is actually of bytes (unsigned char) then:
// Some test data: grey gradient 64x64 pixel image
uchar data[64 * 64 * 3];
int offset = 0;
for (int i = 0; i < 64; ++i) {
for (int j = 0; j < 64; ++j) {
data[offset++] = (i+j)*2;
data[offset++] = (i+j)*2;
data[offset++] = (i+j)*2;
}
}
// Create an image from that
image.save("test.png");
// Some test data: grey gradient 64x64 pixel image
uchar data[64 * 64 * 3];
int offset = 0;
for (int i = 0; i < 64; ++i) {
for (int j = 0; j < 64; ++j) {
data[offset++] = (i+j)*2;
data[offset++] = (i+j)*2;
data[offset++] = (i+j)*2;
}
}
// Create an image from that
QImage image(data, 64, 64, 64 * 3, QImage::Format_RGB888);
image.save("test.png");
To copy to clipboard, switch view to plain text mode
works.
Bookmarks