Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, July 2006
Saving an image


Message 1 in thread

Hi,

I'm having trouble saving a QPainter created image. This is the simple 
code loading an image with QImage, drawing it into an new image and 
saving that:

---------------------------------
int main(int argc, char **argv)
{
    QImage imgSrc("C:/in.png");
    QImage img(imgSrc.width(), imgSrc.height(), QImage::Format_RGB32);
    QPainter painter(&img);

    // Alternative 1:
//    painter.drawImage(QPoint(0, 0), imgSrc);

    // Alternative 2:
    QRectF target(0.0, 0.0, img.width(), img.height());
    QRectF source(0.0, 0.0, img.width(), img.height());
    painter.drawImage(target, imgSrc, source);

    painter.end();
    img.save("C:/out.png", "PNG");
}
---------------------------------

Not much to it, but the result is a corrupted image. The original is 
2400x1200 pixel and so is the copy, but the original image is drawn on 
the copy only to about 5/6 of the width and then repeats the left part. 
Something like [abcdefghij] would get [abcdefgabc]. Does that ring a 
bell? Oh, and I tried it with the same image but rotated by 90deg (now 
it is 1200x2400) and that works, with original and copy identical. As if 
no the original image couldn't be wider than 2200 or so pixel.

Thanks for your help!

Holger

--
 [ signature omitted ] 

Message 2 in thread

On Tuesday July 4 2006 01:35, Holger Stephan wrote:
> int main(int argc, char **argv)
> {
>     QImage imgSrc("C:/in.png");

You have to create a QApplication before using any QtGui features. I once 
asked why I couldn't paint on a QImage without a QApplication and was told 
that "this is the way you have to do it".

--
 [ signature omitted ]