Logo Search packages:      
Sourcecode: qt4-x11 version File versions

bool QPixmap::load ( const QString fileName,
const char *  format = 0,
Qt::ImageConversionFlags  flags = Qt::AutoColor 

Loads a pixmap from the file with the given fileName. Returns true if the pixmap was successfully loaded; otherwise returns false.

The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.

The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the {resources.html}{Resource System} overview for details on how to embed pixmaps and other resource files in the application's executable.

If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.

Note that QPixmaps are automatically added to the QPixmapCache when loaded from a file; the key used is internal and can not be acquired.

See also:
loadFromData(), {QPixmap::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 627 of file qpixmap.cpp.

References QFileInfo::absoluteFilePath(), QPixmapCache::find(), fromImage(), QBitmap::fromImage(), QPixmapCache::insert(), QString::isEmpty(), QImage::isNull(), isNull(), QFileInfo::lastModified(), QString::number(), QFileInfo::size(), and QDateTime::toString().

Referenced by QBitmap::QBitmap(), and QPixmap().

    if (fileName.isEmpty())
        return false;

    QFileInfo info(fileName);
    QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + info.lastModified().toString() + QLatin1Char('_') +
                  QString::number(info.size()) + QLatin1Char('_') + QString::number(data->type);

    if (QPixmapCache::find(key, *this))
        return true;
    QImage image = QImageReader(fileName, format).read();
    if (image.isNull())
        return false;
    QPixmap pm;
    if (data->type == BitmapType)
        pm = QBitmap::fromImage(image, flags);
        pm = fromImage(image, flags);
    if (!pm.isNull()) {
        *this = pm;
        QPixmapCache::insert(key, *this);
        return true;
    return false;

Generated by  Doxygen 1.6.0   Back to index