I want to visualize a matrix of integer values between 0 and 255 as a gray-scale image in Qt 5.12. First, I built a sample 256x256 uchar array with values between 0 and 255 in each row. then I tried to show the image with QImage and format_grayscale as the format. But confusingly, the resulting image contains disturbed pixels in the last rows.
The Resulting Image
I also created a gray-scale color map and tried with format_indexed8, but the same result. Here is my code.
uchar imageArray[256][256];
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
imageArray[i][j] = uchar(j);
}
}
QImage image(&imageArray[0][0],
256,
256,
QImage::Format_Grayscale8);