PDA

View Full Version : how to load a Qt non-supported Image format



Nithya
3rd April 2008, 06:56
I wated to load a 'tiff' image as a background image in the widget.

jpn
3rd April 2008, 07:09
Which version of Qt are you using? As far as I remember, TIFF is supported since Qt 4.3. However, you will have to build the plugin if it's not already built. What does:

qDebug() << QImageReader::supportedImageFormats();
output?

Nithya
3rd April 2008, 07:29
I'm using Qt 4.2.2.And it doesnot support "tiff"
The list of supported formats are only
"bmp", "jpeg", "jpg", "mng", "pbm", "pgm", "png", "ppm", "svg", "xbm", "xpm".

Nithya
3rd April 2008, 07:43
I am now trying with TiffIO plugin to load the Tiff.But I need a general solution to load any kind of non-supported format.Because I have to load dgn format and many other map formats to be loaded.

jpn
3rd April 2008, 07:48
For unsupported formats you will need to provide an image format plugin (http://doc.trolltech.com/4.3/plugins-howto.html#the-higher-level-api-writing-qt-extensions).

Vladd
3rd April 2008, 12:57
I am loading map image using GDAL library. Do this not by plugin. You can see this on https://sourceforge.net/projects/kmapexplorer, file gimgview.cpp function GImgLoader::loadTile.

Map are usually big and program load image block only when request come.

Here code:


pafScanline = (uchar *) CPLMalloc(xsize * ysize * 4);
Q_CHECK_PTR(pafScanline);
for (int i = 1; i <= 3; ++i) { // R G B
GDALRasterBand *poBand;
poBand = m_dataset->GetRasterBand(i);
Q_CHECK_PTR(poBand);
static int smap[4] = { 0, 2, 1, 0 };
if (poBand->RasterIO(GF_Read, x_off, y_off, xsize, ysize,
pafScanline + smap[i], xsize, ysize, GDT_Byte,
4, xsize * 4) == CE_Failure) {
throw gException(QString("RasterIO error:%1").
arg(CPLGetLastErrorMsg()));
}
}
QImage *result = new QImage(xsize, ysize, QImage::Format_RGB32);
Q_CHECK_PTR(result);
for (int y = 0; y < ysize; ++y) {
QRgb *sLine = (QRgb *) result->scanLine(y);
memcpy(sLine, pafScanline + y * xsize * 4, xsize * 4);
}
CPLFree(pafScanline);