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