[Qt-interest] Building an image from raw unsigned char array

Cole, Derek dcole at integrity-apps.com
Wed Jan 19 02:11:12 CET 2011


Also, just to point out, that code I posted using RGB888 causes my application to crash

-----Original Message-----
From: Cole, Derek
Sent: Tue 1/18/2011 8:05 PM
To: Scott Aron Bloom; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Building an image from raw unsigned char array
 

Hello,

Thanks for the reply.

I checked the code and it looks to be in RGB order:

				chars[r][(c)*3] = red;

				chars[r][(c)*3 + 1] = green;

				chars[r][(c)*3 + 2] = blue;

However, I cannot find the enumerated type RGB24 in the QImage specification

Did you mean RGB888?

I think I ahve tried that and had no such luck.


        QImage *qi = new QImage(*imageData, imheight, imwidth, QImage::Format_RGB888);


       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());

Remember, imageData is a unsigned char** so I had to give it a pointer here, or it wouldnt let me use it as an argument.
-----Original Message-----
From: Scott Aron Bloom [mailto:Scott.Bloom at onshorecs.com]
Sent: Tue 1/18/2011 8:01 PM
To: Cole, Derek; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Building an image from raw unsigned char array
 
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/b42dc6a9/attachment.html 


More information about the Qt-interest-old mailing list