Hodza  Ndzaho
Hodza Ndzaho

Reputation: 45

Alternative for QIMAGE function in QTSDK 4.8.4

Is there an alternative for using QImage myImage(w, h, QImage::Format_ARGB32); in Qt? (w and h are width and height of imported picture)?

This is the code:

if (tif) {
          uint32 w, h;

          TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
          TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
          QImage myImage(w, h, QImage::Format_ARGB32);

          if (!myImage.isNull()) {
            if (TIFFReadRGBAImage(tif, w, h, reinterpret_cast<uint32 *>(myImage.bits()), 0)) {
                myImage = myImage.rgbSwapped();
                myImage = myImage.mirrored();
            }
            else {

                   return ImageStatePtr(0);
            }

           }

           TIFFClose(tif);
           ImageStatePtr ptr = ImageStatePtr(new ImageState(QFileInfo(filename).fileName(), myImage));
           return ptr;

    }
    else return ImageStatePtr(0);
}

I need to replace QImage with alternative that have the same function. For some reason, i am not allowed to use QImage in my project.

Upvotes: 0

Views: 272

Answers (1)

Boris Dalstein
Boris Dalstein

Reputation: 7788

If you want to import an image, you probably want this:

QImage::QImage ( const QString & fileName, const char * format = 0 );

That you can simply use this way:

QImage myImage("test.png");

You can also use a QPixmap instead:

QPixmap myPixmap("test.png");

QImage and QPixmap are useful for different tasks. The documentaion says:

Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. The isQBitmap() function returns true if a QPixmap object is really a bitmap, otherwise returns false. Finally, the QPicture class is a paint device that records and replays QPainter commands.

Upvotes: 1

Related Questions