【发布时间】:2016-02-13 16:07:48
【问题描述】:
在我的项目中,我需要将具有多种颜色的图像转换为仅使用我在自定义 colorTable 中设置的 144 种预定颜色中的任何一种的图像。
这是我的代码:
QImage convImage(128, 128, QImage::Format_Indexed8);
convImage.setColorCount(144);
convImage.setColorTable(colorTable); //colorTable is a const QVector with 144 qRgb values.
//scaledImage is the source image
convImage = scaledImage.convertToFormat(QImage::Format_Indexed8,Qt::ThresholdDither|Qt::AutoColor);
ui->mapView->setPixmap(QPixmap::fromImage(convImage));
我希望 convImage 仅包含我创建的 colorTable 中存在的颜色,但它似乎完全忽略了我设置的表,而是创建了它自己的唯一表,最大颜色为 256 种。
我可以通过循环遍历每个像素来自己索引所有内容,并找到一种从 colorTable 中准确选择颜色的方法,但我想知道我是否只是使用了 colorTable 错误。我在文档中找不到任何解释为什么要创建新表的内容。
感谢您的宝贵时间。
【问题讨论】:
标签: c++ qt qimage color-space