QImage :: scaleHeight转换模式返回NULL图像

时间:2014-01-16 06:32:11

标签: c++ qt scaling qtgui qimage

我正在尝试将图像尺寸调整为120X240。

image = image.scaledToHeight(120);
image = image.scaledToWidth(240);

对于某些尺寸为837x630的图片,请输入错误

QImage::scaleHeight: Image is a null image
QImage::scaleWidth: Image is a null image

有些图像正确剥落,尺寸几乎相同(837X 642) 这些错误的原因是什么。有些图像正在缩放,有些图像没有...为什么?

1 个答案:

答案 0 :(得分:0)

QImage的构造函数以某种方式构建 null图像。您应该使用QImage::isNull来处理这种情况:

if (image.isNull())
    // throw error

你也应该这样做:

image = QImage(image.scaled(240, 120));

代替。