I try to superpose 3 QImage but I have some warnings, for example :
QImage::pixelColor: coordinate (31,30) out of range
And the result of the blending is a black image.
Here my code :
QBrush MainWindow::blendLayer(int x, int y){
QImage blend(m_layer1_data[x][y]->background().textureImage());
QImage l2(m_layer2_data[x][y]->background().textureImage());
QImage l3(m_layer3_data[x][y]->background().textureImage());
for(int a = 0; a < blend.width(); a++){
for(int b = 0; b < blend.height(); b++ ){
blend.setPixelColor(a,b,blendColor(blend.pixelColor(a,b),l2.pixelColor(a,b),l3.pixelColor(a,b)));
}
}
QBrush brush(blend);
return brush;
}
QColor MainWindow::blendColor(QColor c2, QColor c1){
QColor c3;
c3.setRed(((c1.red()+c2.red())/2)%256);
c3.setGreen(((c1.green()+c2.green())/2)%256);
c3.setBlue(((c1.blue()+c2.blue())/2)%256);
c3.setAlpha(((c1.alpha()+c2.alpha())/2)%256);
return c3;
}
QColor MainWindow::blendColor(QColor c1, QColor c2, QColor c3){
return blendColor(c3,blendColor(c1,c2));
}
Is there an easy way to superposing some QImage ? Thanks for your help
l2
andl3
? – eyllanescm_layer1_data[x][y]
,m_layer2_data[x][y]
andm_layer3_data[x][y]
? – eyllanescQPainter
does all the blending you want, and it's fast. Your code also doesn't compile as shown. You'll have to change the alpha of the source images and then simply draw them on top of each other. Painter can change the alpha too, so all operations will be quick and accelerated using SIMD. When using the painter, the sizes of source images don't matter as long as they make sense for your application. – Kuba hasn't forgotten MonicaQBrush
. – Kuba hasn't forgotten Monica