[Qt-interest] Get raw data from QImage
Cole, Derek
dcole at integrity-apps.com
Thu Apr 28 01:37:18 CEST 2011
Sorry - accidentallly sent last mail.
As I was saying, I want to get the raw data back out of a section of the QGraphicsItem, so I used code like this:
QPixmap fullPmap = topItem->pixmap();
fullPmap = fullPmap.copy(isec.toRect());
QImage chip = fullPmap.toImage();
so I know that chip has the right section in it, because I can use "display code" like I just posted with chip as the image instead of qi, and it works.
However, I need to get the raw data back from chip, so that I can send it off to another 3rd party library that is expecting a single unsigned char *
In my case, as you can see from the way I created the image in the display code below, I just want to send it a single band, since it has been displayed as grayscale anyway.
I tried to use chip.bits() but that is giving me some data that is unusable, apparently, or I am using it wrong.
So what is the proper way to do this?
________________________________
From: Cole, Derek
Sent: Wednesday, April 27, 2011 7:33 PM
To: qt-interest at qt.nokia.com
Subject: Get raw data from QImage
Hello,
I have populated a QGraphicsPixmapItem with an image using code similar to the following:
QImage *qi = new QImage(imwidth, imheight, QImage::Format_RGB32);
for (int i = 0 ; i < imheight ; i++)
{
for (int j = 0 ; j < imwidth ; j++)
{
qi->setPixel(j,i,qRgb(imageData[i*imwidth+j],imageData[i*imwidth+j],imageData[i*imwidth+j]));
}
}
QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));
if(scene.items().contains(item)){
scene.removeItem(item);
item->~QGraphicsItem();
}
item = new ImagePixmapItem(p);
scene.addItem(item);
Now I want to get the data back from one of those QGraphicsItems and I am using some code like this to get the QImage of a particular part of the image:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110427/e8e0a61d/attachment.html
More information about the Qt-interest-old
mailing list