我试图理解为什么下面的代码会改变 Qt 中的 QImage。它不打算做任何事情(还),它只是为了测试。当我在带有 alpha 的图像上运行代码时,alpha 通道会丢失并被黑色背景替换。
QImage image;
image.load("image.png");
for (int y = 0; y < image.height(); y++) {
for (int x = 0; x < image.height(); x++) {
QColor c = QColor::fromRgba(image.pixel(x, y));
c.setHsv(c.hue(), c.saturation(), c.value());
image.setPixel(x, y, c.rgba());
}
}
这是我注释掉该行时的结果image.setPixel(...)
:
这是该image.setPixel(...)
行的结果:
我希望我的代码不会对图像进行任何更改。知道为什么要这样做吗?