我有一个图像,我试图使用QImage::transform ( const QTransform &matrix,Qt::TransformationMode模式)const方法来转换图像的选定部分。但是该方法返回空图像。Qt也写到std输出:
"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。
发布于 2013-12-10 23:39:11
QImage工作得很好。问题在于你的转变。尝试下面的代码来检查:
qDebug() << transform.map(QRectF(0, 0, img.width(), img.height())).boundingRect();如果图像为100x100,则返回QRectF(-2.21401e+08,-1.9792e+08 2.21401e+08x1.97921e+08)。很明显,这么大的图像不能保存在内存中。你需要纠正你的转换,这样它就可以将你的图像缩放到合理的大小。我不知道这些神奇的数字是从哪来的,但是试着弄到新的。
而且,img = img.scaled(img.width(), img.height());显然没有任何效果(将图像缩放到它已经拥有的大小有什么意义?)与painter相关的代码似乎不完整,但这可能是一个复制粘贴问题。
https://stackoverflow.com/questions/20503820
复制相似问题