1

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()?

UniversE
  • 555
  • 2
  • 7
  • 25

3 Answers3

2

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.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
1

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.

jantar
  • 183
  • 2
  • 9
  • Is nothing except the pixel values used to compare? I've checked the [source](http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/image/qimage.cpp) but not sure. – UniversE Aug 19 '13 at 12:57
1

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.

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
  • Is nothing except the pixel values used to compare? I've checked the [source](http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/image/qimage.cpp) but not sure. – UniversE Aug 19 '13 at 12:58
  • 1
    I think it compares all info first like format of a picture, and only then if it matches it checks pixels. If it works fast it means it didn't check pixels :). – jantar Aug 19 '13 at 13:10