oliverliu.hz
10th February 2011, 07:41
I confused about line 15.
If commented it, the code will create a pixmap filled with many circle. That is named resultA.
If it works, the code creates a pixmap that contents is balloon + circle. That is named resultB.
Why?
I think the painter variable is not relevant with QImage instances tmpdi and image, just only relevant displayImage instance.
Can anyone give me any suggestions to explain it?
Thanks!
int main (int argc, char** argv)
{
QSize resultSize(281,377);
QSize pegSize(21,29);
QImage image;
image.load("balloon.jpg");
QImage tmpdi;
tmpdi = image.scaled(resultSize,Qt::KeepAspectRatio);
// tmpdi = image.scaled(QSize(resultSize.width()*1.5, resultSize.height()*2.0),Qt::KeepAspectRatio);
QImage displayImage= QImage(resultSize,QImage::Format_ARGB32_Premultipl ied);
QPainter painter1(&displayImage);
painter1.fillRect(QRect(0,0,resultSize.width(),res ultSize.height()), Qt::transparent);
float ratioPegX = resultSize.width() * 1.0 / pegSize.width();
float ratioPegY = resultSize.height() * 1.0 / pegSize.height();
//draw circle on it
for (int pegi = 0; pegi < pegSize.width(); pegi++)
for (int pegj = 0; pegj <pegSize.height(); pegj++)
{
QRectF rectf = QRectF( pegi * ratioPegX, pegj * ratioPegY,
ratioPegX, ratioPegY);
painter1.drawEllipse(rectf.center(), ratioPegX/2.0, ratioPegY/2.0);
}
displayImage.save("x3.png");
return 0;
}
If commented it, the code will create a pixmap filled with many circle. That is named resultA.
If it works, the code creates a pixmap that contents is balloon + circle. That is named resultB.
Why?
I think the painter variable is not relevant with QImage instances tmpdi and image, just only relevant displayImage instance.
Can anyone give me any suggestions to explain it?
Thanks!
int main (int argc, char** argv)
{
QSize resultSize(281,377);
QSize pegSize(21,29);
QImage image;
image.load("balloon.jpg");
QImage tmpdi;
tmpdi = image.scaled(resultSize,Qt::KeepAspectRatio);
// tmpdi = image.scaled(QSize(resultSize.width()*1.5, resultSize.height()*2.0),Qt::KeepAspectRatio);
QImage displayImage= QImage(resultSize,QImage::Format_ARGB32_Premultipl ied);
QPainter painter1(&displayImage);
painter1.fillRect(QRect(0,0,resultSize.width(),res ultSize.height()), Qt::transparent);
float ratioPegX = resultSize.width() * 1.0 / pegSize.width();
float ratioPegY = resultSize.height() * 1.0 / pegSize.height();
//draw circle on it
for (int pegi = 0; pegi < pegSize.width(); pegi++)
for (int pegj = 0; pegj <pegSize.height(); pegj++)
{
QRectF rectf = QRectF( pegi * ratioPegX, pegj * ratioPegY,
ratioPegX, ratioPegY);
painter1.drawEllipse(rectf.center(), ratioPegX/2.0, ratioPegY/2.0);
}
displayImage.save("x3.png");
return 0;
}