Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to load TGA file?
QPixmap *pixmap = new QPixmap(u8"C:\\Users\\mycom\\Downloads\\sample.tga"); QLabel *label = new QLabel(this); label->setPixmap(*pixmap); label->resize(pixmap->width(), pixmap->height()); label->move(0, 0); label->show();
I tried to load a TGA file using QPixmap like above, but nothing is displayed.
ICO files were not displayed either. BMP, PNG files were displayed well.
qDebug() << QImageReader::supportedImageFormats();
When I call a QImageReader::supportedImageFormats() method, I could get a string like.
("bmp", "cur", "gif", "icns", "ico", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")
My plugin directory path is "C:\Qt\Qt5.14.2\5.14.2\msvc2017\plugins\imageformats" and there are qtga.dll and qtgad.dll.
And I called a QApplication::addLibraryPath() method with the path as argument, but It's not working as well.
Could you tell me why it doesn't work? Thanks.
Maybe the tga file has a format the plugin does not understand. Take a look if you can see something on stdout.
btw: you're leaking *pixmap - no need to create it on the heap at all.
This post is deleted!
MT339M last edited by MT339M
Thank you for your quick answer. I can see a message 'C:\Qt\Qt5.14.2\5.14.2\msvc2017\plugins\imageformats\qtgad.dll' file is loaded on stdout. But there was no other information on stdout. I used a tga image on https://filesamples.com/formats/tga. I'm quite confused. 😂
qDebug() << pixmap.width(); qDebug() << pixmap.height();
The above code outputs zero.
I have tested with images on https://filesamples.com/categories/image. BMP, CUR, GIF, ICO, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, WBMP, WEBP, XBM and XPM file formats were all well displayed. (The previously tested ICO file was also well printed. The image was so small that I thought It is not printed.) But only the TGA file is not displayed. Would you mind testing with that file? Thanks.
(Oh, thank you for your advice to make QPixmap object on stack.)
The plugin only supports 8, 16 or 24 bit color uncompressed tga files.
Thank you for your reply :) The file's header is:
00 00 02 00 00 00 00 00 00 00 00 00 80 02 AA 01 18 00
I think it's a 24 bit color uncompressed tga file (0x02 and 0x18). Is there something I'm wrong with?
@MT339M Looks fine, maybe some other unreadable stuff. Can you provide this tga file?, what does QImage::isNull() return?
The size is 0x280/0x1aa = 640/426 with 24bpp, correct?
- IsNull() method return true.
- Yes, your interpretation of the header is right.
Oh, I'm sorry I thought you knew the image's URL. the image's URL is https://filesamples.com/samples/image/tga/sample_640×426.tga.
It's no Truevision TGA' file as it seems ( https://en.wikipedia.org/wiki/Truevision_TGA#File_footer_(optional) ). The plugin checks for this existence and refuses to load it if it is not found.
Sadly the error message can not be moved up and is not printed to stdout through qWarning(). I will provide a patch for this.
Thank you. I think I have to find out the point where the error occurs in QT's source code. Thank you for the patch, too.
I think I have to find out the point where the error occurs in QT's source code.
Why? It will not help you - the tga file has to be Truevision 2.0 compliant which is not according the plugin so..)
MT339M last edited by MT339M
I didn't mean to say that. I'm sorry I didn't speak very well. I tried to determine which part of the file did not meet the specification. I saw the part where it check the footer, so I attached the footer, and the problem was found.
Oh I got it. You already gave me a link related to footer. (I just recognized it as a tga document. I didn't recognize the anchor.) I had passed it. I checked it right now.