0
votes

I am creating QGraphicsPixmapItems by loading images from files.

bool PixMapItem::loadItemFromFile(const QString &filename)
{
    QPixmap p;
    if(!p.load(filename))
        return false;
    setPixmap(p);
#ifdef NOT_QT_4
    m_itemSize = p.size()/p.devicePixelRatio();
#else
    m_itemSize = p.size();
#endif
    return true;
}

caller:

item->loadItemFromFile(filename);
item->adjustForMaxSize(maxSize);

I would like to know how the memory used by the item depends on the image file size.

1) Type of image - will the encoding of the Pixmap stored in the item be minimal, or always 32 bit, or is there any way to set it ?

2) Assuming the item is resized immediately after load to match a specific size (see above), would the actual image size affect the item memory size ? Would memory size be better if I scale the pixmap instead of the item itself ?

1

1 Answers

1
votes

Let me try to answer it, maybe it help you :

  1. I have try long time ago and yes it will always 32 bit, it will be RGB or RGBA (if there is alpha on image, it can be check by hasAlpha). The way you can check is check the depth of the QPixmap which always return 32. Nothing we can do with the pixmap data because it handle internally, which stated on their QPixmap documentation :

Note that the pixel data in a pixmap is internal and is managed by the underlying window system.

  1. Smaller image will be smaller memory consumed. And you need to free your original pixmap after scale it.

QPixmap is design for painting performance on screen, if you want better handle IO (formating image, decrease the color, etc) use QImage. You also able to render QImage to screen using the painter but it will be slower compare to QPixmap.