PDA

View Full Version : QPainter and QImage



beerkg
7th September 2006, 14:26
Hi, I'm trying to save somthing I draw using QPainter to image file. My code looks like that:

QImage image(800,600,QImage::Format_RGB32);
QPainter paint;
paint.begin(&image);
paint.drawRect(10,10,50,50);
paint.end();
image.save("image.bmp");

What I get is a totally black image with some different colours strips. But when I use existing image like that:

QImage image("image.bmp");
QPainter paint;
paint.begin(&image);
paint.drawRect(10,10,50,50);
paint.end();
image.save("image.bmp");

ewerything is fine. I don't know where is the problem. Maybe you will have some ideas. Thanks in avance.

jpn
7th September 2006, 14:31
The first image will be constructed as black (default) and you are drawing a rect with black pen&brush (default).

wysota
7th September 2006, 14:48
In other words try adding image.fill(Qt::white) after you construct the object.

beerkg
7th September 2006, 14:48
Big thanks for fast reply. I haven't noticed that, now it is working correct. Tell me if it's posible to construct image as white?