Hi guys,
I've wrote this piece of code that should make the black part of an image into a blue part. But the code doesn't change the black into the blue it never comes in the if test I think.
Could someone help me?
int height, width;
background.load("Background.png");
world.fill(1);
sizeImage = background.size();
width = sizeImage.width();
height = sizeImage.height();
const QRgb black = 0;
const QRgb blue = 255;
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
if (background.pixel(x,y) == black) {
background.setPixel(x,y,blue);
}
}
}
painter.drawImage(0,0,background);
//adding new image to the graphicsScene
scene->addItem(&item);
view.show();
QImage background;
QImage world(1500, 768, QImage::Format_RGB32);
QSize sizeImage;
int height, width;
background.load("Background.png");
world.fill(1);
QPainter painter(&world);
sizeImage = background.size();
width = sizeImage.width();
height = sizeImage.height();
const QRgb black = 0;
const QRgb blue = 255;
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
if (background.pixel(x,y) == black) {
background.setPixel(x,y,blue);
}
}
}
painter.drawImage(0,0,background);
//adding new image to the graphicsScene
QGraphicsPixmapItem item( QPixmap::fromImage(background));
QGraphicsScene* scene = new QGraphicsScene;
scene->addItem(&item);
QGraphicsView view(scene);
view.show();
To copy to clipboard, switch view to plain text mode
Kind regards,
Bookmarks