Question

I have two QImage objects which should be equal but the result of QImage::operator== is false. So I want to print all the raw data of the two objects for the comparison. How to do that? Can it be done with qDebug()?

Was it helpful?

Solution 2

If You want to print values of each pixel, then use bits() method of QImage to get pointer to all pixel values in unsigned char and just print them in for loop. For example if You have 32-bit pictures then in table returned by bits() You will have 4 values for each pixel (Red, Green, Blue, Alpha) and to know how many of those You have just use width()*height()*4 (if it's 32-bit depth). Or You can compare every single pixel instead of printing and return only those which differ.

OTHER TIPS

I suggest you write a function to compare the two images, byte by byte, and return the offset where they are different.

Comparing image data by hand is often tedious and can lead to mistakes.

Using qDebug() << QImage() will print out something like QImage(QSize(0, 0) ).

You could use the const uchar * QImage::constBits() function to get a pointer to the first pixel data, and then iterate through the pixel data, printing the values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top