Q::p ixel:坐标(75,3039)超出范围
QImage::pixel: coordinate (75,3039) out of range
由于某种原因,由于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 上转义文件路径中的-
破折号的规则是什么,但要么是图像中的破折号没有被打开和加载,要么是其他地方的路径是错误的。检查硬盘上是否存在映像。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 尝试通过多个向量访问变量时,向量下标超出范围
- 错误:未在此范围内声明'reverse'
- 正在将指针转换为范围
- 使用std::transform将一个范围的元素添加到另一个范围中
- 在基于范围的for循环中使用结构化绑定声明
- 如何计算数据类型的范围,例如int
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 在C++中查找范围的长度
- 如何设置一个范围来提取我想要获得的信息
- 并行用于C++17中数组索引范围内的循环
- 为左值和右值的包装器实现C++范围
- 求出有多少个数字是完美平方,而sqrt()是L,R范围内的素数
- 关于:C++中异常对象的范围:为什么我没有得到副本?
- 超出范围时使用对象
- 不计算一个范围内的完美数
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- 基于范围的 for 循环:迭代使用一个元素扩展的向量
- 如何访问超出其块范围的对象?
- Q::p ixel:坐标(75,3039)超出范围