35 lines
924 B
C++
35 lines
924 B
C++
|
#include "imageresize.h"
|
||
|
#include <QDebug>
|
||
|
|
||
|
ImageResize::ImageResize()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
QImage ImageResize::fixedResize(QImage image, int width, int height, bool keepRatio, bool doNotEnlarge)
|
||
|
{
|
||
|
if ((image.width() > width) || (image.height() > height) || (doNotEnlarge == false))
|
||
|
{
|
||
|
if (width < 0 || height < 0)
|
||
|
{
|
||
|
width = image.width();
|
||
|
height = image.height();
|
||
|
}
|
||
|
if (keepRatio)
|
||
|
{
|
||
|
image = image.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
image = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||
|
}
|
||
|
}
|
||
|
return image;
|
||
|
}
|
||
|
|
||
|
QImage ImageResize::pergentageResize(QImage image, int width, int height)
|
||
|
{
|
||
|
image = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||
|
|
||
|
return image;
|
||
|
}
|