I managed to display the image in the label in Qt using something like the following:
transformPixels(0,0,1,imheight,imwidth,1);//sets unsigned char** imageData unsigned char* fullCharArray = new unsigned char[imheight * imwidth]; for (int i = 0 ; i < imheight ; i++) for (int j = 0 ; j < imwidth ; j++) fullCharArray[(i*imwidth)+j] = imageData[i][j]; QImage *qi = new QImage(fullCharArray, imwidth, imheight, QImage::Format_RGB32); ui->viewLabel->setPixmap(QPixmap::fromImage(*qi,Qt::AutoColor));
So, fullCharArray is an array of unsigned characters that were mapped from an imageData 2D array, in other words, it is imheight * imwidth bytes.
The problem is that only part of my image is displayed on the label. The image is very large. I would like to display the full image, reduced to fit the label, while maintaining the aspect ratio.
Also, this QImage format was the only one I could find that seemed to give me a close idea of ββthe image I want to display - is that what I should expect? I use only one byte per pixel (unsigned char - values ββfrom 0 to 255), and it seems that liek RGB32 does not make much sense for this data type, but none of the others displays anything remotely correct
edit: Following dan gallaghers advice, I implemented this code:
QImage *qi = new QImage(fullCharArray, imwidth, imheight, QImage::Format_RGB32); int labelWidth = ui->viewLabel->width(); int labelHeight = ui->viewLabel->height(); QImage small = qi->scaled(labelWidth, labelHeight,Qt::KeepAspectRatio); ui->viewLabel->setPixmap(QPixmap::fromImage(small,Qt::AutoColor));
But this leads to the fact that my program "unexpectedly ends" code 0