title: Displaying and sizing a grayscale from a QImage in Qt
body: <p>I have been able to display an image in a label in Qt using something like the following:</p>
  
  <pre><code>transformPixels(0,0,1,imheight,imwidth,1);//sets unsigned char** imageData
  
  unsigned char* fullCharArray = new unsigned char[imheight * imwidth];
       for (int i = 0 ; i &lt; imheight ; i++)
           for (int j = 0 ; j &lt; imwidth ; j++)
                  fullCharArray[(i*imwidth)+j] = imageData[i][j];
  
  QImage *qi = new QImage(fullCharArray, imwidth, imheight, QImage::Format_RGB32);
  
  ui-&gt;viewLabel-&gt;setPixmap(QPixmap::fromImage(*qi,Qt::AutoColor));
  </code></pre>
  
  <p>So fullCharArray is an array of unsigned chars that have been mapped from the 2D array imageData, in other words, it is imheight * imwidth bytes. </p>
  
  <p>The problem is, it seems like only a portion of my image is showing in the label. The image is very large. I would like to display the full image, scaled down to fit in the label, with the aspect ratio preserved.</p>
  
  <p>Also, that QImage format was the only one I could find that seemed to give me a close representation of the image I am wanting to display, is that what I should expect? I am only using one byte per pixel (unsigned char - values from 0 to 255), and it seems liek RGB32 doesnt make much sense for that data type, but none of the other ones displayed anything remotely correct</p>
  
  <p>edit:
  Following dan gallaghers advice, I implemented this code: </p>
  
  <pre><code>QImage *qi = new QImage(fullCharArray, imwidth, imheight, QImage::Format_RGB32);
  int labelWidth = ui-&gt;viewLabel-&gt;width();
  int labelHeight = ui-&gt;viewLabel-&gt;height();
  
  QImage small = qi-&gt;scaled(labelWidth, labelHeight,Qt::KeepAspectRatio);
  ui-&gt;viewLabel-&gt;setPixmap(QPixmap::fromImage(small,Qt::AutoColor));
  </code></pre>
  
  <p>But this causes my program to "unexpectedly finish" with code 0</p>