I have a QImage that I built from a pixmap something like the following:
QPixmap fullPmap = topItem->pixmap();
fullPmap = fullPmap.copy(isec.toRect());
QImage chip = fullPmap.toImage();
This is basically intersecting with a rectangle on screen to crop the image to a chipped size.
I now need to get the character array representing that data back from chip.
How can I do this?
I tried something like this:
unsigned char * data = chip.bits();
And when I display "data" I get a completely distorted image, nothing like my actual chip.
fullPmap is an RGB image if that matters. I have some code that I am using to convert it to grayscale:
QRgb col;
int gray;
for (int i = 0; i < chip.width(); ++i)
{
for (int j = 0; j < chip.height(); ++j)
{
col = chip.pixel(i, j);
gray = qGray(col);
chip.setPixel(i, j, qRgb(gray, gray, gray));
}
}
Which I don't really like, but it seemed like the easiest way to do such a thing.
Displaying the data that is returned from bits() looks like this:
imwidth = chip.width();
imheight = chip.height();
QImage *qi = new QImage(imwidth, imheight, QImage::Format_RGB32);
// #pragma omp parallel for
for (int i = 0 ; i < imheight ; i++)
for (int j = 0 ; j < imwidth ; j++)
{
qi->setPixel(j,i,qRgb(data[i*imwidth + j],data[i*imwidth + j],data[i*imwidth + j]));
}