#include #include #include inline std::ostream& operator<<( std::ostream &s, const QImage::Format &_format) { switch (_format) { case QImage::Format_RGB32: return (s << "Format_RGB32"); case QImage::Format_RGB888: return (s << "Format_RGB888"); case QImage::Format_Grayscale8: return (s << "Format_Grayscale8"); default: return (s << _format); } } int main(int argc, char *argv[]) { QDir dir("C:/Testdata/QImageissue"); QStringList filters; filters << "*.jpg" << "*.png"; QStringList files = dir.entryList(filters,QDir::Files | QDir::NoDotAndDotDot); QImage _qimg, _tmpqimg; for(int i = 0; i < files.size(); ++i) { std::cout << i << ") " << files.at(i).toStdString() << std::endl; _qimg.load(dir.absoluteFilePath(files.at(i))); std::cout << "\tOriginal format:\t" << _qimg.format() << "\tDepth: " << _qimg.depth() << " bits" << std::endl; std::cout << "\tOriginal width:\t" << _qimg.width() << "\n\tOriginal height:\t" << _qimg.height() << std::endl; std::cout << "\tOriginal byteCount():\t" << _qimg.byteCount() << "\n\tOriginal width() x height() x depth()/8:\t" << _qimg.width() * _qimg.height() * _qimg.depth()/8 << "\n\tOriginal extra bytes (diff between two above): " << _qimg.byteCount() - _qimg.width() * _qimg.height() * _qimg.depth()/8 << std::endl << std::endl; if(_qimg.format() == QImage::Format_RGB888) { _tmpqimg = _qimg; } else { _tmpqimg = std::move(_qimg.convertToFormat(QImage::Format_RGB888)); std::cout << "\tConverted to format:\t" << _tmpqimg.format() << "\tDepth: " << _tmpqimg.depth() << " bits" << std::endl; } std::cout << "\tWidth:\t" << _tmpqimg.width() << "\n\tHeight:\t" << _tmpqimg.height() << std::endl; std::cout << "\tbyteCount():\t" << _tmpqimg.byteCount() << "\n\twidth() x height() x depth()/8:\t" << _tmpqimg.width() * _tmpqimg.height() * _tmpqimg.depth()/8 << "\n\tExtra bytes (diff between two above): " << _tmpqimg.byteCount() - _tmpqimg.width() * _tmpqimg.height() * _tmpqimg.depth()/8 << std::endl << std::endl; } return 0; }