若该文为原创文章,转载请注明出处
本文章博客地址: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