How can I convert pixel data in QImage to another format?

跟風遠走 提交于 2019-12-13 00:19:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!