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

bool QPixmap::loadFromData ( const uchar *  data,
uint  len,
const char *  format = 0,
Qt::ImageConversionFlags  flags = Qt::AutoColor 

Loads a pixmap from the len first bytes of the given binary data. Returns true if the pixmap was loaded successfully; 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.

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.

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

Definition at line 628 of file qpixmap.cpp.

References fromImage(), QBitmap::fromImage(), QByteArray::fromRawData(), isNull(), and QBuffer::open().

Referenced by loadFromData(), and QTextDocument::loadResource().

    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);
    QBuffer b(&a);

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

Generated by  Doxygen 1.6.0   Back to index