[Qt-interest] Building an image from raw unsigned char array
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Wed Jan 19 05:07:39 CET 2011
If you want to use the QImage( uchar *....) it will need to be
contiguous...
Otherwise, create the QImage for the correct format, and use scanLien to
file it in
Scott
From: Cole, Derek [mailto:dcole at integrity-apps.com]
Sent: Tuesday, January 18, 2011 7:26 PM
To: Scott Aron Bloom; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Building an image from raw unsigned char
array
The thought had crossed my mind. I think I have tried this already, but
I am not at work to verify. I got the data[][] array from the library
call, created the new array as you suggested, and then manually mapped
data[][] into the new 1D array using i*w + j to map (i,j)
I will give it a try using the RGB888 format again, just to ensure that
is what went on.
Thanks for the help, I will report back tomorrow
-----Original Message-----
From: qt-interest-bounces+dcole=integrity-apps.com at qt.nokia.com on
behalf of Scott Aron Bloom
Sent: Tue 1/18/2011 10:02 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Building an image from raw unsigned char
array
Why not allocate it as
Unsigned char * data = new unsigned char[ H * W * 3 ];
and just send in data to the QImage constructor
From: Cole, Derek [mailto:dcole at integrity-apps.com]
Sent: Tuesday, January 18, 2011 6:56 PM
To: Scott Aron Bloom; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Building an image from raw unsigned char
array
What do you mean definition? The allocation part? If so:
unsigned char** data = new unsigned char * [H]
for (int i = 0; i < H; i++)
data[i] = new unsigned char[W*3]
where H and W are the image height and width in pixels
I then populate it as i showed earlier:
loop over rows
loop over cols
data[row][(col)*3] = red;
data[row][(col)*3 + 1] = green
data[row][(col)*3 + 2] = blue;
I have tried a few different combinations of ways to get this data to
display, with a few different formats, and every one of them has
something wrong with the display, or crashes the app.
Incidentally, I am pretty sure the data array is correct, because the
method that returns data also writes that same data array to a file that
is formatted for NITF, and the NITF viewer can open it, and I can see it
correctly in the NITF viewer. That is how I am able to verify the
results to know that the display is coming out incorrectly.
Derek
-----Original Message-----
From: Scott Aron Bloom [mailto:Scott.Bloom at onshorecs.com]
Sent: Tue 1/18/2011 8:40 PM
To: Cole, Derek; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Building an image from raw unsigned char
array
Yes I meant 888 sorry.. was going from memory...
If its crashing.. MOST likely, you have a size issue problem
What is definition of the data?
From: Cole, Derek [mailto:dcole at integrity-apps.com]
Sent: Tuesday, January 18, 2011 5:11 PM
To: Cole, Derek; Scott Aron Bloom; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Building an image from raw unsigned char
array
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/5a2f01bd/attachment.html
More information about the Qt-interest-old
mailing list