【发布时间】:2013-12-28 12:31:30
【问题描述】:
我有一个图像,我正在尝试使用 QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode) const 方法转换图像的选定部分。 但是这个方法返回空图像。 Qt 还写入标准输出:
“Qimage:内存不足,返回空图像。”
QImage img;
img.load("D:\\3.png");
QPolygonF polygonIn;
polygonIn << QPointF(73, 63)
<< QPointF(362, 22)
<< QPointF(517, 325)
<< QPointF(1, 210);
QPolygonF polygonOut;
polygonOut << QPointF(45, 39)
<< QPointF(228, 13)
<< QPointF(228, 198)
<< QPointF(180, 198);
QTransform transform;
auto isOk = QTransform::quadToQuad(polygonIn, polygonOut, transform);
if(!isOk)
throw std::runtime_error("Transformation impossible with such parameters.");
auto result = img.transformed(transform, Qt::TransformationMode::SmoothTransformation);
我尝试调试 QImage 源。 qimage.cpp第6633行
QImage dImage(wd, hd, target_format);
QIMAGE_SANITYCHECK_MEMORY(dImage);
wd 和 hd 值很大。
也许有人知道我可以如何解决这个问题。顺便说一句,我使用 qt 4.8.4。
【问题讨论】:
-
图片的宽度和高度是多少?据我所知,如果它们大于 ~32000 像素,加载这样的图像可能会出现问题。
-
我的输入图像是 s29.postimg.org/k45fwbmsn/Untitled.png 我想将其转换为黄色多边形 s9.postimg.org/3rcfnjej3/Untitled_Transform.png 这点实际上是角坐标。
-
您的多边形绝对不正确,并且会产生比例因子 ~1e+6 的异常变换。这就是你得到空图像的原因。
标签: c++ image qt image-processing qimage