如何将QImage中的像素数据转换为其他格式? [英] How can I convert pixel data in QImage to another format?
问题描述
我使用任意 QImage :: Format
获得 QImage
的实例。我怎样才能用我选择的特定的 QImage :: Format
创建另外一个 QImage
的实例,这样实际的图像数据是从任意格式转换为我的格式?
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);
如果可能的话,我正在寻找一种方法来处理Qt中的现有代码(而不是写我自己的像素格式转换例程工作在低级别)。
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).
推荐答案
为什么不使用 convertToFormat ?它几乎与你所要求的语法相同,不过它是 QImage
的成员,所以你只能以格式传递。
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.
这篇关于如何将QImage中的像素数据转换为其他格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!