更新:此行似乎产生错误:* line = color;
我收到以下错误但我不明白它可以来自哪里:
错误:
HEAP [testQt.exe]: 堆积在0B444FE8处修改为0B44C6B0过去要求的大小为76c0
生成它的行:
return QPixmap::fromImage(qimage);
来自:
QPixmap Interpolation::getData() {
QPointF pt(0, 0);
QRgb color;
QImage qimage(m_width, m_height, QImage::Format_ARGB32);
qimage.fill(Qt::transparent);
for (int i(0); i < m_height; ++i) {
m_progress->setValue(m_width+i);
QRgb *line = (QRgb *)qimage.scanLine(i);
for (int j(0); j < m_width; ++j) {
pt.setX(j);
pt.setY(i);
line += 1;
if (isInHull(pt)) {
color = colorScale(interp(&pt));
*line = color; //If I remove this part the program won't crash
}
}
}
return QPixmap::fromImage(qimage);
}
如果有帮助:
QRgb Interpolation::colorScale(qreal value)
{
int cat;
cat = qFloor(qreal(9)*(value-m_min)/(m_max-m_min));
return m_couleurs[cat];
}
使用:
m_couleurs[0] = qRgb(247, 252, 240);
m_couleurs[1] = qRgb(224, 243, 219);
m_couleurs[2] = qRgb(204, 235, 197);
m_couleurs[3] = qRgb(168, 221, 181);
m_couleurs[4] = qRgb(123, 204, 196);
m_couleurs[5] = qRgb(78, 179, 211);
m_couleurs[6] = qRgb(43, 140, 190);
m_couleurs[7] = qRgb(8, 104, 172);
m_couleurs[8] = qRgb(8, 64, 129);
任何领导都将不胜感激。
编辑:添加完整功能以防万一。 Edit2:使代码更清晰,删除了无用的部分。 Edit3:更新了问题。
答案 0 :(得分:6)
在将颜色指定给*行之前,您会前进行。因此,当j = 0时,您实际上是在您写入缓冲区末尾的最后一条扫描线的最后一个像素的末尾设置像素1。
将行+ = 1移动到循环的末尾。