简体   繁体   English

如何将QImage中的像素数据转换为另一种格式?

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

I receive an instance of QImage with arbitrary QImage::Format . 我收到带有任意QImage::FormatQImage实例。 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? 如何使用选择的特定QImage::Format创建另一个QImage实例,以便将实际图像数据从任意格式转换为我的格式?

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). 我正在寻找一种在可能的情况下使用Qt中现有代码执行此操作的方法(这与编写自己的低级像素格式转换例程相反)。

Why not use convertToFormat ? 为什么不使用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. 尽管它是QImage的成员,但它的语法几乎与您要求的语法相同,因此您只能传递格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM