Hi I have a very simple question, suppose that I have a 2D 50 x 50 array consisting of say, pixel values (0-255), and I want to save this as image, how do I actually do it?

I've tried:

Qt Code:
  1. QImage image;
  2. QRgb value;
  3.  
  4. // a 2d array named arr with size 50 x 50 including its values was declared earlier
  5.  
  6. for (int i=0;i<maxwidth;i++)
  7. {
  8. for (int j=0;j<maxheight;j++)
  9. {
  10. // set the rgb value based on arrs' value
  11. // set them all the same to make em grayscale?
  12. value = qRgb(arr[i][j],arr[i][j],arr[i][j]);
  13. image.setPixel(i,j,value);
  14. }
  15. }
  16.  
  17. image.save("test.jpg",".jpg");
To copy to clipboard, switch view to plain text mode 

I suspect there is more than just setting the pixel values using QImage::setPixel. Am I missing something else? Thanks in advance.