[Qt-interest] Building an image from raw unsigned char array
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Wed Jan 19 02:01:52 CET 2011
You can go a couple of ways..
First, make sure the image format ia RGB24, and not BGR 24
Second if its truly RGB24
QImage img( const uchar * data imageData, width, height,
QImage::Format_RGB24 )
Should work,
Note MOST times, when I have had to deal with this, there is type cast
issue on imageData.. its an int * of 32bits, and so my indexing is
skipping a ton of values
Scott
From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of Cole, Derek
Sent: Tuesday, January 18, 2011 4:52 PM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] Building an image from raw unsigned char array
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/984bcb90/attachment.html
More information about the Qt-interest-old
mailing list