本文共 1322 字,大约阅读时间需要 4 分钟。
当小窗口在图片上方时,显示放大的局部图片,效果如下图所示:
源码下载地址:
注意:图片是按原图比例显示的,图片显示时已经位移或者缩放了,需要重新计算子图像位置。
1 下方图片的显示
在paintEvent中显示:
QPixmap pixmap("c:/patch-src.png");
painter.drawPixmap(0,0,pixmap);
2 获取小窗口下面的图像
为了加快速度,先从原图获取部分图像,然后再将获取到的子图像放大。
QImage _subImage;
getRectSubPix(_srcImage,_curInnerRect.center(),_curInnerRect.width(),_curInnerRect.height(),_subImage);
QImage _scaledImage = _subImage.scaled(_subImage.width() * _ratio,_subImage.height() * _ratio,Qt::KeepAspectRatio,Qt::SmoothTransformation);
QPoint _scaledCenter = QPoint(_scaledImage.width() /2 ,_scaledImage.height() / 2);
getRectSubPix(_scaledImage,_scaledCenter,_curInnerRect.width(),_curInnerRect.height(),scaledSubImage);
3 小窗口中显示放大的图像
QImage _grayImage(this->scaledSubImage.size(),QImage::Format_Alpha8);
_grayImage.fill(250);
this->scaledSubImage.setAlphaChannel(_grayImage);
QPixmap pixmap = QPixmap::fromImage(this->scaledSubImage);
QRect _drawRect;
if (this->outerWindow != nullptr){
_drawRect.setTopLeft(this->rect().topLeft());
_drawRect.setBottomRight(this->rect().bottomRight());
}
if (this->innerWindow != nullptr){
_drawRect.setTopLeft(this->mapFromParent(this->innerWindow->geometry().topLeft()));
_drawRect.setBottomRight(this->mapFromParent(this->innerWindow->geometry().bottomRight()));
}
_drawRect.adjust(sr,sr,-sr,-sr);
painter.drawPixmap(_drawRect,pixmap);
转载地址:https://blog.csdn.net/hulinhulin/article/details/121417358 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!