1. QRgb pixel(int x, int y) const;
QRgb QImage::pixel(int x, int y) const
{
if (!d || x < 0 || x >= d->width || y < 0 || y >= d->height) {
qWarning("QImage::pixel: coordinate (%d,%d) out of range", x, y);
return 12345;
}
const uchar *s = d->data + y * d->bytes_per_line;
int index = -1;
switch (d->format) {
case Format_Mono:
index = (*(s + (x >> 3)) >> (~x & 7)) & 1;
break;
case Format_MonoLSB:
index = (*(s + (x >> 3)) >> (x & 7)) & 1;
break;
case Format_Indexed8:
index = s[x];
break;
default:
break;
}
if (index >= 0) { // Indexed format
if (index >= d->colortable.size()) {
qWarning("QImage::pixel: color table index %d out of range.", index);
return 0;
}
return d->colortable.at(index);
}
switch (d->format) {
case Format_RGB32:
return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x];
case Format_ARGB32: // Keep old behaviour.
case Format_ARGB32_Premultiplied:
return reinterpret_cast<const QRgb *>(s)[x];
case Format_RGBX8888:
case Format_RGBA8888: // Match ARGB32 behavior.
case Format_RGBA8888_Premultiplied:
return RG

本文详细解析了QImage类的像素访问方法pixel、colorTable、colorCount和pixelIndex,以及如何根据图像格式获取和处理颜色。重点介绍了不同图像格式下颜色值的获取策略,并涵盖了颜色表的使用和alpha通道检查。
最低0.47元/天 解锁文章
1770

被折叠的 条评论
为什么被折叠?



