功能:
加载图片,实现对图片的缩放、旋转、镜像翻转
核心实现:
//放大图片,比例可自行调节
void ImgProcessor::ShowZoomIn()
{
if(img.isNull())
return;
QMatrix martix;
martix.scale(2,2);
img = img.transformed(martix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
//缩小图片,比例自行调节
void ImgProcessor::ShowZoomOut()
{
if(img.isNull())
return;
QMatrix matrix;
matrix.scale(0.5,0.5);
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
//按角度旋转图片
void ImgProcessor::ShowRotate90()
{
if(img.isNull())
return;
QMatrix matrix;
matrix.rotate(90);
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
//垂直镜像翻转
void ImgProcessor::ShowMirrorVertical()
{
if(img.isNull())
return;
img=img.mirrored(false,true);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
//水平镜像翻转
void ImgProcessor::ShowMirrorHorizontal()
{
if(img.isNull())
return;
img=img.mirrored(true,false);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}