问题
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).
回答1:
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.
来源:https://stackoverflow.com/questions/43105753/how-can-i-convert-pixel-data-in-qimage-to-another-format