问题描述
我想这更像是一个图形操作问题,但我想在Qt(c ++)中完成。如果我有一张图片 - 让我们只是在透明背景上说一个浅灰色的圆圈,Qt中是否有内置的功能来将色调/饱和度转换为彩色?
I suppose this is more of a graphics manipulation question in general, but I'd like to accomplish this in Qt (c++). If I have an image - let's just say a circle on a transparent background - of a light gray color, is there any built-in functionality in Qt to shift the hue / saturation to color it?
我想我可以逐像素地去修改rgb,在数学上增加x到r,g和b,以得到想要的颜色,但必须有一个比修改每一个像素更好的方法。
I suppose I could go pixel by pixel, and modifying the rgb mathematically - add x to r, g, and b, to get a desired color, but there must be a better way than modifying every single pixel.
Qt Docs没有任何东西可以用于图像处理,只是改变alpha和颜色。我应该看看一个开源库吗(最终结果可能是一个独立销售的软件)?如果是这样,有什么建议吗?或者是否有隐藏在Qt文档中的秘密功能,可以在不需要外部库/疯狂算法的情况下完成?
Nothing in the Qt Docs goes this far into image manipulation, just altering alpha and colors. Should I look into an open source library (the end result will likely be an independently sold software)? If so, are there any recommendations? Or is there a secret function hidden in the Qt docs that can accomplish without the need of outside libraries / crazy algorithms?
推荐答案
一种可能的行动方式:
A possible course of action:
- 执行
QImage
使用颜色表获取带索引的
QImage :: convertToFormat(QImage :: Format_Indexed8)
图像
- 使用
QRgb
获取颜色表格值QImage :: color(int i)const - 使用
QColor
和其他QColor方法操作颜色
(QRgb颜色) li> - 将颜色
表改为void QImage :: setColor(int index,QRgb colorValue)
- Load your image as a QImage
- Do a
QImageQImage::convertToFormat(QImage::Format_Indexed8)
to get a indexedimage with a color table - Get color table values with
QRgbQImage::color ( int i ) const
- Manipulate the colors with
QColor( QRgb color )
and the other QColor methods - Alter the colortable with
void QImage::setColor ( int index, QRgb colorValue )
这篇关于改变QImage / QPixmap的色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!