Answer the question
In order to leave comments, you need to log in
How to use QT to display a 10-bit image on the monitor?
Good afternoon. The Qt 5.13 snapshot was recently released, making the QImage ::Format_Grayscale16 format available to QImage . About a year ago, I already had to work with QImage , but then it was only about 8-bits. Since I have a 10-bit monitor at work, I decided to try to create and display a 1024x400 gradient on it, in which each pixel should be one tone lighter than the previous one (2^10=1024). By forming a QByteArray like this:
QByteArray *ArrayGenerator::gen10bitArr()
{
QByteArray *arr = new QByteArray();
uint8_t partA;
uint8_t partB;
for (int row = 0; row < 400; row++) {
for (uint16_t color = 0; color < 1024; color++) {
partA = static_cast<uint8_t>((color &0xFF00) >> 8);
partB = static_cast<uint8_t>(color &0x00FF);
arr->append (partA);
arr->append (partB);
}
}
return arr;
}
QImage &MainWindow::gen10bitImg(QByteArray*data, int width, int height)
{
QImage * img = new QImage((uchar*)data->data (),
width, height, 2048, QImage::Format_Grayscale16);
img->save ("image.png");
return *img;
}
Answer the question
In order to leave comments, you need to log in
partA = static_cast<uint8_t>((color &0xFF00) >> 8); // == 0 всегда
partB = static_cast<uint8_t>(color &0x00FF); // 0..255
for (ushort color = 0; color < 1024; color++)
arr->append (color * 64); // * 65536/1024
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question