PDA

View Full Version : how to draw a image of size 600x400



sar_van81
12th March 2007, 09:11
hi,

can anyone say me how to draw an image of size 600x400. i tried as follows


QPainter p( this );
uint x,y;
x=550;
y=500;
QImage image(x,y,32 );
image.setAlphaBuffer( true );
for ( uint j =0; j <x; j++ )
{
for ( uint i =0; i <y; i++ )
{
QRgb pixel;
pixel = qRgb(0,0,255);
image.setPixel( i, j, pixel );
}
}
p.drawImage(QPoint(0,0),image,0);


when i executed this it said the following error:
"
QImage::scanLine: Index 500 out of range
Segmentation fault ".

but i can succesfuly draw an image of size 500x500.
can anyone say me why is that so ..

thanks in advance,

saravanan

Lykurg
12th March 2007, 10:45
Hi,

seems to that you have to swap i and j:
image.setPixel( j, i, pixel );

Lykurg


EDIT: or you must say j<y and i<x.

sar_van81
12th March 2007, 11:11
hi,

thank you for the reply.now i got it working.