1.QImage scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
/*!
\fn QImage QImage::scaledToWidth(int width, Qt::TransformationMode mode) const
Returns a scaled copy of the image. The returned image is scaled
to the given \a width using the specified transformation \a
mode.
This function automatically calculates the height of the image so
that its aspect ratio is preserved.
If the given \a width is 0 or negative, a null image is returned.
\sa {QImage#Image Transformations}{Image Transformations}
*/
QImage QImage::scaledToWidth(int w, Qt::TransformationMode mode) const
{
if (!d) {
qWarning("QImage::scaleWidth: Image is a null image");
return QImage();
}
if (w <= 0)
return QImage();
Q_TRACE_SCOPE(QImage_scaledToWidth, w, mode);
qreal factor = (qreal) w / width();
QTransform wm = QTransform::fromScale(factor, factor);
return transformed(wm, mode);
}
QTransform QTransform::fromScale(qreal sx, qreal sy)
{
#ifndef QT_NO_DEBUG
if (qIsNaN(sx) | qIsNaN(sy)) {
nanWarning("fromScale");
return QTransform();
}
#endif
QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1);
if (sx == 1. && sy == 1.)
transform.m_type = TxNone;
else
transform.m_type = TxScale;
transform.m_dirty = TxNone;
return transform;
}
QTransform(qreal h11, qreal h12, qreal h13,

本文详细介绍了QImage类的scaledToWidth和scaledToHeight方法,用于按指定宽度和高度缩放图像,同时保持图像比例。内容涉及了QTransform的使用,包括缩放因子计算、矩阵变换及不同模式下的图像处理。此外,还涵盖了图像转换的复杂性和性能优化考虑。
最低0.47元/天 解锁文章
1237

被折叠的 条评论
为什么被折叠?



