主要使用到计算灰度索引值的函数qGray()
```
for (int i = 0; i < srcImage.width(); i++)
{
for (int j= 0; j < srcImage.height(); j++)
{
QRgb color = srcImage.pixel(i, j);
int gray = qGray(color);
srcImage.setPixel(i, j, qRgba(gray, gray, gray, qAlpha(color)));
}
}
```
需要完整代码请访问
QtWidgetsExamples