项目实战:Qt图像拼接渐进色图层生成工具v1.0.0(预设四路拼接,多路可通过多图叠层实现)

若该文为原创文章,转载请注明出处

本文章博客地址:https://hpzwl.blog.csdn.net/article/details/146068951

长沙红胖子Qt(长沙创微智科)博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬结合等等)持续更新中...

Qt开发专栏:项目实战(点击传送门)

需求

图像拼接需要过渡模板:

1.预设四路渐进色拼接

2.可单独一路或者多路,配合多图层算法,实现多路过度

3.可调整点过渡位置,过渡间隙

4.可调整点过渡颜色

5.6路/8路拼接可通过调整点位置和多图层渐进色实现

背景

公司自研产品过程中产出生产工具,无需求助美工或者懂切图,提升工作效率。

Demo:gardientColorTool_v1.0.0 windows运行包

CSDN粉丝0积分下载:https://mp.csdn.net/mp_download/manage/download/UpDetailed

QQ群:博主名or博客首页扫码进入QQ技术群,点击"文件"搜索"gardientColorTool",群内与博文同步更新)

核心源码

cpp 复制代码
void GradientPainterWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    // 绘制背景颜色
    drawBackground(&painter);
    drawImage(&painter);
    drawPoint(&painter);

    QWidget::paintEvent(event);
}

void GradientPainterWidget::drawBackground(QPainter *painter)
{
    painter->save();

    painter->setPen(Qt::NoPen);
    painter->setBrush(_backgroundColor);
    painter->drawRect(rect());

    painter->restore();
}

void GradientPainterWidget::drawImage(QPainter *painter)
{
    if(_image.isNull())
    {
        LOG << "if(_image.isNull())";
        return;
    }
    painter->save();

    painter->drawImage(rect(), _image);

    painter->restore();
}

void GradientPainterWidget::drawPoint(QPainter *painter)
{
    painter->save();

    painter->setPen(Qt::NoPen);
    painter->setBrush(QColor(0, 0, 0, 255));
    for(int index = 0; index < _listInterPointF.size(); index++)
    {
        painter->drawEllipse(_listInterPointF.at(index), _offset, _offset);
    }

    painter->restore();
}

void GradientPainterWidget::updatePoint()
{
    // 求交点
    _listInterPointF.clear();
    for(int index = 0; index < _listAngle.size(); index++)
    {
        double degrees = _listAngle.at(index);
        // 中心点延伸线
        double x = rect().center().x() - sin(qDegreesToRadians(degrees)) * rect().width();
        double y = rect().center().y() - cos(qDegreesToRadians(degrees)) * rect().width();
        QLineF line(QPoint(x, y), rect().center());
//        LOG << degrees << QPoint(x, y);
        for(int lineIndex = 0; lineIndex < _listBoundLineF.size(); lineIndex++)
        {
//            LOG << line << _listBoundLineF.at(lineIndex);
            QPointF interPos(0, 0);
            QLineF::IntersectType type = _listBoundLineF.at(lineIndex).intersect(line, &interPos);
            if(type == QLineF::BoundedIntersection)
            {
//                LOG << "inter" << interPos;
                _listInterPointF.append(interPos);
                break;
            }
        }
    }
}

void GradientPainterWidget::updateImage()
{
    if(_image.isNull())
    {
        LOG << "if(_image.isNull())";
        return;
    }
    _image = QImage(rect().width(), rect().height(), QImage::Format_ARGB32);

    QConicalGradient conicalGradient;
    conicalGradient.setCenter(rect().center());
    conicalGradient.setAngle(90);

    conicalGradient.setColorAt(0.0, _color0);
    conicalGradient.setColorAt(1.0, _color0);

    conicalGradient.setColorAt(_angle  / 360, _color);
    conicalGradient.setColorAt(_angle2 / 360, _color2);

    conicalGradient.setColorAt(_angle3 / 360, _color3);
    conicalGradient.setColorAt(_angle4 / 360, _color4);

    conicalGradient.setColorAt(_angle5 / 360, _color5);
    conicalGradient.setColorAt(_angle6 / 360, _color6);

    conicalGradient.setColorAt(_angle7 / 360, _color7);
    conicalGradient.setColorAt(_angle8 / 360, _color8);

    QPainter painter(&_image);
    painter.setPen(Qt::NoPen);
    painter.setBrush(conicalGradient);
    painter.drawRect(rect());

    update();
}

本文章博客地址:https://hpzwl.blog.csdn.net/article/details/146068951

相关推荐
小短腿的代码世界5 小时前
Qt日志系统深度解析:从qDebug到企业级日志框架
开发语言·qt
Morwit10 小时前
QML组件之间的通信方案(暴露子组件)
c++·qt·职场和发展
金色熊族14 小时前
解析QTransform的用法
qt
追烽少年x16 小时前
Qt多线程编程:QThread与QtConcurrent的对比与应用
qt
小短腿的代码世界1 天前
Qt实时盈亏计算深度解析:从持仓数据到动态盈亏展示
开发语言·qt
Python私教1 天前
GenericAgent PySide6 桌面应用深度解析:悬浮按钮 + 聊天面板的原生 Qt 方案
开发语言·数据库·qt
用户805533698031 天前
现代Qt开发教程(新手篇)1.11——定时器
c++·qt
小短腿的代码世界1 天前
Qt券商接口封装深度解析:统一API设计与多源适配
开发语言·qt·单元测试
T0uken1 天前
基于 vcpkg 与 LLVM-MinGW 的 Qt6 静态链接开发方案
c++·windows·qt
Ulyanov1 天前
《现代 Python 桌面应用架构实战:PySide6 + QML 从入门到工程化》 开发环境搭建与工具链极简主义 —— 拒绝臃肿,构建工业级基座
开发语言·python·qt·ui·架构·系统仿真