qimage copy函数怎么使用
答案:2 悬赏:80 手机版
解决时间 2021-03-18 13:45
- 提问者网友:遮云壑
- 2021-03-18 00:16
qimage copy函数怎么使用
最佳答案
- 五星知识达人网友:琴狂剑也妄
- 2021-03-18 00:26
虽然我很聪明,但这么说真的难到我了
全部回答
- 1楼网友:轻雾山林
- 2021-03-18 01:01
举个小例子:
#include "qqlevel.h"
QQLevel::QQLevel(QWidget *parent)
: QWidget(parent)
{
setFixedSize(300, 200);
level_button = new QPushButton();
grade_button = new QPushButton();
//分别获取0-9数字图标
QPixmap pixmap_0 = getPixmap(QString(":/level/level_value"), 10, 0);
QPixmap pixmap_1 = getPixmap(QString(":/level/level_value"), 10, 1);
QPixmap pixmap_2 = getPixmap(QString(":/level/level_value"), 10, 2);
QPixmap pixmap_3 = getPixmap(QString(":/level/level_value"), 10, 3);
QPixmap pixmap_4 = getPixmap(QString(":/level/level_value"), 10, 4);
QPixmap pixmap_5 = getPixmap(QString(":/level/level_value"), 10, 5);
QPixmap pixmap_6 = getPixmap(QString(":/level/level_value"), 10, 6);
QPixmap pixmap_7 = getPixmap(QString(":/level/level_value"), 10, 7);
QPixmap pixmap_8 = getPixmap(QString(":/level/level_value"), 10, 8);
QPixmap pixmap_9 = getPixmap(QString(":/level/level_value"), 10, 9);
int count = 3;
int pixmap_width = pixmap_8.width();
int pixmap_height = pixmap_8.height();
//最前面LV图标
QPixmap pixmap_lv(":/level/lv");
int lv_width = pixmap_lv.width();
QPixmap total_pixmap(QSize(pixmap_width*count + lv_width, pixmap_height));
QPainter painter(&total_pixmap);
//绘制LV图标
painter.drawPixmap(QRect(0, 0, lv_width, pixmap_height), pixmap_lv);
//再绘制LV888图标
for(int i=0; i
{
painter.drawPixmap(QRect(lv_width+pixmap_width*i, 0, pixmap_width, pixmap_height), pixmap_8);
}
level_button->setFixedHeight(30);
level_button->setIcon(total_pixmap);
level_button->setIconSize(total_pixmap.size());
//分别获取皇冠、太阳、月亮、星星、...等图标
QPixmap pixmap_grade_0 = getPixmap(QString(":/level/grade"), 5, 0);
QPixmap pixmap_grade_1 = getPixmap(QString(":/level/grade"), 5, 1);
QPixmap pixmap_grade_2 = getPixmap(QString(":/level/grade"), 5, 2);
QPixmap pixmap_grade_3 = getPixmap(QString(":/level/grade"), 5, 3);
QPixmap pixmap_grade_4 = getPixmap(QString(":/level/grade"), 5, 4);
//绘制5个皇冠
int grade_count = 5;
int pixmap_grade_width = pixmap_grade_0.width();
int pixmap_grade_height = pixmap_grade_0.height();
QPixmap total_grade_pixmap(QSize(pixmap_grade_width*grade_count, pixmap_grade_height));
QPainter grade_painter(&total_grade_pixmap);
for(int i=0; i
{
grade_painter.drawPixmap(QRect(pixmap_grade_width*i, 0, pixmap_grade_width, pixmap_grade_height), pixmap_grade_0);
}
grade_button->setFixedHeight(30);
grade_button->setIcon(total_grade_pixmap);
grade_button->setIconSize(total_grade_pixmap.size());
QVBoxLayout *main_layout = new QVBoxLayout();
main_layout->addStretch();
main_layout->addWidget(level_button);
main_layout->addWidget(grade_button);
main_layout->addStretch();
main_layout->setSpacing(20);
main_layout->setContentsMargins(0, 0, 0, 0);
setLayout(main_layout);
}
QQLevel::~QQLevel()
{
}
QPixmap QQLevel::getPixmap(QString pixmap_name, int count, int index)
{
QPixmap final_pixmap;
if(!pixmap_name.isEmpty() && count > 0)
{
QPixmap pixmap(pixmap_name);
int pixmap_width = pixmap.width()/count;
int pixmap_height = pixmap.height();
final_pixmap = pixmap.copy(pixmap_width*index, 0, pixmap_width, pixmap_height);
}
return final_pixmap;
}
合并过程中有可能会出现背景变色,稍作处理即可!
QImage pixmap(QSize(this->width()*WINDOW_PAGE_COUNT, WINDOW_HEIGHT), QImage::Format_ARGB32_Premultiplied);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(pixmap.rect(), Qt::transparent);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
for(int i = 0; i < WINDOW_PAGE_COUNT; i++)
{
painter.drawImage(QRect(WINDOW_WIDTH*i, 0, WINDOW_WIDTH, WINDOW_HEIGHT),
QImage(QString(":/newCharacter/newFeature_%1").arg(i)));
}
total_label = new QLabel(this);
total_label->resize(pixmap.size());
total_label->setPixmap(QPixmap::fromImage(pixmap));
total_label->move(WINDOW_START_X, WINDOW_START_Y);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯