Change pixels in an image.
-
Hi guys,
i'm having a QImage worldImage in my class as private var, when i use my damage function
it draws a black circle on the worldImage that works fine, here is the code for that part:@//function to add damage to the land
void World::damage(int x, int y)
{
QPainter painter(&worldImage);
painter.setBrush(QBrush(Qt::black));
painter.drawEllipse(x,y,150,100);
item = new QGraphicsPixmapItem(QPixmap::fromImage(worldImage));
this->addItem(item);
putWorm(this->x, this->y);
}then after the black circle is on i need to update my world and i would use this function
void World::updateWorld()
{for(int k = 0; k < height; k++) { for(int l = 0; l < width; l++) { color = worldImage.pixel(k,l); if (qRed(color) == 0 && qGreen(color) == 0 && qBlue(color) == 0) { worldImage.setPixel(k,l,QColor(Qt::blue).rgb()); bitmap[k][l] = 0; } else bitmap[k][l] = 1; } }
}@
this makes my bitmap for collision detection up to date and where the black circle is, it's going to be blue.
But the code doesn't work, it sais it is out of range with every pixel , and if i ask the height and width of the image
it is still the same image. Is it not possible to change the image this way do i need to create a new one or ...?Kind regards,
-