kaydknight
29th December 2007, 03:00
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:
QImage image;
QRgb value;
// a 2d array named arr with size 50 x 50 including its values was declared earlier
for (int i=0;i<maxwidth;i++)
{
for (int j=0;j<maxheight;j++)
{
// set the rgb value based on arrs' value
// set them all the same to make em grayscale?
value = qRgb(arr[i][j],arr[i][j],arr[i][j]);
image.setPixel(i,j,value);
}
}
image.save("test.jpg",".jpg");
I suspect there is more than just setting the pixel values using QImage::setPixel. Am I missing something else? Thanks in advance.
I've tried:
QImage image;
QRgb value;
// a 2d array named arr with size 50 x 50 including its values was declared earlier
for (int i=0;i<maxwidth;i++)
{
for (int j=0;j<maxheight;j++)
{
// set the rgb value based on arrs' value
// set them all the same to make em grayscale?
value = qRgb(arr[i][j],arr[i][j],arr[i][j]);
image.setPixel(i,j,value);
}
}
image.save("test.jpg",".jpg");
I suspect there is more than just setting the pixel values using QImage::setPixel. Am I missing something else? Thanks in advance.