c++ Qt绘制传热云图
#ifndef THERMAL_COLOR_MAP_H #define THERMAL_COLOR_MAP_H #include <QVector> #include <QColor> class ThermalColorMap { public: ThermalColorMap() { // 冷色调到热色调渐变 colors << QColor(0, 0, 255) // 冷蓝 << QColor(0, 255, 255) // 青 << QColor(0, 255, 0) // 绿 << QColor(255, 255, 0) // 黄 << QColor(255, 128, 0) // 橙 << QColor(255, 0, 0); // 热红 } QColor getColor(double value) const { if (colors.isEmpty()) return Qt::white; if (value <= 0) return colors.first(); if (value >= 1) return colors.last(); int index = static_cast<int>(value * (colors.size() - 1)); QColor start = colors[index]; QColor end = colors[index + 1]; double ratio = value * (colors.size() - 1) - index; return QColor::fromRgbF( start.redF() * (1 - ratio) + end.redF() * ratio, start.greenF() * (1 - ratio) + end.greenF() * ratio, start.blueF() * (1 - ratio) + end.blueF() * ratio ); } private: QVector<QColor> colors; }; #endif // THERMAL_COLOR_MAP_H

#############################
QQ 3087438119

浙公网安备 33010602011771号