【发布时间】:2015-07-25 08:11:49
【问题描述】:
我有两张图片。我需要将图像相互叠加/重叠。第一个图像或基础图像的大小为 160x128,让第二个图像为 120x100。如何相互重叠?
这是我的代码,我把它当作参考:
#include "mainwindow.h"
#include <QApplication>
#include "mainwindow.h"
#include <QPixmap>
#include <QFile>
#include <QLabel>
#include <QPainter>
QLabel *lbl= NULL ;
QImage baseImage("/usr/image1.jpg");
QImage overlayLogoff("/usr/image2.jpg");
QImage createImageWithOverlay(const QImage& baseImage, const QImage& overlayImage)
{
QImage imageWithOverlay = QImage(baseImage.size(), QImage::Format_RGB16);
QPainter painter(&imageWithOverlay);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(imageWithOverlay.rect(), Qt::transparent);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 0, baseImage);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 0, overlayImage);
painter.end();
return imageWithOverlay;
}
QImage logoffImage = createImageWithOverlay(baseImage, overlayLogoff);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
lbl = new QLabel();
createImageWithOverlay(baseImage, overlayLogoff);
return a.exec();
}
在这里我无法获得任何图像?我是否需要使用显示功能来显示图像。
请帮忙。谢谢
【问题讨论】: