2

I receive an instance of QImage with arbitrary QImage::Format. How can I create another instance of QImage with a particular QImage::Format of my choosing so that the actual image data is converted from the arbitrary format to my format?

Example:

QImage convertFormat(const QImage &inputImage, QImage::format outputFormat)
{
    // What comes here?
}

//Usage
QImage converted = convertFormat(mySourceImage, QImage::Format_Grayscale8);

I am looking for a way to do this with existing code in Qt if possible (as opposed to writing my own pixel format conversion routines working on the low level).

Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95

1 Answers1

6

Why not use convertToFormat? It has nearly the same syntax as you requested, though it's a member of QImage so you'd only pass in the format.

artoonie
  • 822
  • 5
  • 14