bool DdrawCircleOnImage( const QString &inputImagePath, const QString &outputImagePath, QVector<QPoint> dotData ) { if ( inputImagePath.isEmpty() || outputImagePath.isEmpty() ) { qWarning("输入图片路径无效!"); return false; } // 加载图像 QImage image(inputImagePath); if (image.isNull()) { qWarning("加载图像失败"); return false; } // 创建一个 QPainter 对象 QPainter painter(&image); QPen pen(Qt::red); pen.setWidth(3); painter.setPen(pen); for ( auto dot : dotData ) { float coeffX = dot.x() / 1224.0; float coeffY = dot.y() / 756.0; int x = image.width() * coeffX; int y = image.height() * coeffY; painter.drawEllipse( x, y, 20, 20 ); } // 保存修改后的图像 if (!image.save(outputImagePath)) { qWarning("Failed to save image"); } return true; }
标签:return,qt,另存为,image,qWarning,pen,dot,图片 From: https://www.cnblogs.com/RedWetPlace/p/18349562