1.scaled()
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode mode = Qt::FastTransformation) const
{ return scaled(QSize(w, h), aspectMode, mode); }
/*!
\fn QImage QImage::scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode,
Qt::TransformationMode transformMode) const
Returns a copy of the image scaled to a rectangle defined by the
given \a size according to the given \a aspectRatioMode and \a
transformMode.
\image qimage-scaling.png
\list
\li If \a aspectRatioMode is Qt::IgnoreAspectRatio, the image
is scaled to \a size.
\li If \a aspectRatioMode is Qt::KeepAspectRatio, the image is
scaled to a rectangle as large as possible inside \a size, preserving the aspect ratio.
\li If \a aspectRatioMode is Qt::KeepAspectRatioByExpanding,
the image is scaled to a rectangle as small as possible
outside \a size, preserving the aspect ratio.
\endlist
If the given \a size is empty, this function returns a null image.
\sa isNull(), {QImage#Image Transformations}{Image
Transformations}
*/
QImage QImage::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const
{
if (!d) {
qWarning("QImage::scaled: Image is a null image");
return QImage();
}
if (s.isEmpty())
return QImage();
QSize newSize = size();
newSize.scale(s, aspectMode);
newSize.rwidth() = qMax(newSize.width(), 1);
newSize.rheight() = qMax(newSize.height(), 1);
if (newSize == size())
return *this;
Q_TRACE_SCOPE(QImage_scaled, s, aspectMode, mode);
QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
QImage img = transformed(wm, mode);
return img;
}
/*!
Returns a copy of the image that is transformed using the given
transformation \a matrix and transformation \a mode.
The returned image will normally have the same {Image Formats}{format} as
the original image. However, a complex transformation may result in an
image where not all pixels are covered by the transformed pixels of the
original image. In such cases, those background pixels will be assigned a
transparent color value, and the transformed image will be given a format
with an alpha channel, even if the orginal image did not have that.
The transformation \a matrix is internally adjusted to compensate
for unwanted translation; i.e. the image produced is the smallest
image that contains all the transformed points of the original
image. Use the trueMatrix() function to retrieve the actual matrix
used for transforming an image.
Unlike the other overload, this function can be used to perform perspective
transformations on images.
\sa trueMatrix(), {QImage#Image Transformations}{Image
Transformations}
*/
QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode ) const
{
if (!d)
return QImage();
Q_TRACE_SCOPE(QImage_transformed, matrix, mode);
// source image data
const int ws =

本文档详细介绍了QImage类的scaled()和transformed()两个方法,用于图像的缩放和复杂变换。scaled()方法根据指定的比例模式和变换模式调整图像大小,而transformed()则允许进行更复杂的透视变换。此外,还展示了rgbSwapped_helper()方法,用于将图像的RGB颜色通道进行交换。这些函数广泛应用于图像处理和显示中。
最低0.47元/天 解锁文章
1768

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



