0

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.

Boris Dalstein
  • 7,015
  • 4
  • 30
  • 59
  • 1
    Why do you need an alternative? Only then can one figure out what alternative to give (if any). – Kuba hasn't forgotten Monica Sep 04 '13 at 23:18
  • You have to tell us what exactly you are trying to achieve, and even more why on earth you can't use QImage? (If this is for an homework, mention it). Otherwise, we can't know what else you can use or not (can you use QPixmap??), and what is adapted to your specific problem. – Boris Dalstein Sep 05 '13 at 00:46
  • Thx for having moved the code and additional information where it belongs, now it is much cleaner :-) Anyway, it is only when you tell us what you are trying to achieve in the end, and why you are not allowed to use `QImage` that one can advise you on an alternative. – Boris Dalstein Sep 05 '13 at 18:37
  • It is some kind of special plugin for an application we are creating, and for some unknown reason I am not allowed to use QImage. I need to make this code working by not using that funcion. – Hodza Ndzaho Sep 08 '13 at 00:43

1 Answers1

1

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.

Boris Dalstein
  • 7,015
  • 4
  • 30
  • 59