[Qt-interest] Building an image from raw unsigned char array
Cole, Derek
dcole at integrity-apps.com
Wed Jan 19 01:52:22 CET 2011
Hello,
I have image data coming in from a C++ function as an unsigned char**
It was defined to he H*W*3 in size, so there are 3 values for each pixel - a Red Green and Blue
How is the best way to pull this data in to Qt so taht it can be displayed in a label?
I thought I could use
QImage *qi = new QImage(imwidth, imheight, QImage::Format_ARGB32);
for (int i = 0 ; i < imheight ; i++)
for (int j = 0 ; j < imwidth ; j++)
{
qi->setPixel(j,i,qRgb(imageData[i][j],imageData[i][j+1],imageData[i][j+2]));
j+=3;
}
QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));
QPixmap p1(p.scaled(ui->menuBar->width(),ui->menuBar->width(), Qt::KeepAspectRatio, Qt::SmoothTransformation ));
ui->viewLabel->setPixmap(p1);
ui->viewLabel->setFixedHeight(p1.height());
ui->viewLabel->setFixedWidth(p1.width());
But this gives me distorted results. imageData is what holds the unsigned char** passed back from the other function.
Thanks in advance
derek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110118/2dd3ca1a/attachment.html
More information about the Qt-interest-old
mailing list