Q::p ixel:坐标(75,3039)超出范围

QImage::pixel: coordinate (75,3039) out of range

本文关键字:3039 范围 ixel 坐标      更新时间:2023-10-16

由于某种原因,由于QImage::pixel: coordinate (75,3039) out of range,我无法运行我的代码。但是我不知道我应该怎么做才能修复此错误,我试图在网上搜索不成功。

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    int height;
    int width;
    unsigned char *p, *p_begin;
    QImage img("C:\Users\Owner\Pictures\2013-09-26\IMG_0836.JPG");
    height = img.height();
    width = img.width();
    p = (unsigned char *)malloc(height * width * sizeof(unsigned char));
    p_begin = p;
    for (int row = 1; row < 2000 + 1; ++row)
        for (int col = 1; col < 2000 + 1; ++col)
        {
            QColor clrCurrent( img.pixel( row, col ));
            *p = (unsigned char)((clrCurrent.green() * 0.587) +  (clrCurrent.blue() * 0.114) + (clrCurrent.red() * 0.299));
            p++;
        }
}

查看源代码:

Qt 4.x:链接

if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
    qWarning("QImage::pixel: coordinate (%d,%d) out of range", x, y);
    return 12345;
}

Qt 5.x:链接

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;
}

在这两种情况下,d为 null 也是您看到消息的原因。这,在操作图像之前检查if (!img.isNull())。我不确定在 Windows 上转义文件路径中的-破折号的规则是什么,但要么是图像中的破折号没有被打开和加载,要么是其他地方的路径是错误的。检查硬盘上是否存在映像。