简体   繁体   中英

QImage from HBITMAP

In my windows-only program, I use a third-party library, which returns a HBITMAP .

Is there a way to initialize a QImage from its contents, ie to convert it to a QImage ?

This is the way to do it for Qt 4 (QtGui):

QImage image(QPixmap::fromWinHBITMAP(hBitmap).toImage());

This is the way to do it for Qt 5 (QtWinExtras):

QPixmap pixmap = QtWin::fromHBITMAP(hBitmap);
QImage image = pixmap.toImage();

// or

QtWin::imageFromHBITMAP(hdc, hBitmap, width, height)

好的,这似乎对我有用:

QImage image(QPixmap::fromWinHBITMAP(hBitmap).toImage());

Qt5 without Extras: Put before your code

#include <QPixmap>
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat=0);

and in your function, for example

QPixmap pixmap = qt_pixmapFromWinHBITMAP(LoadBitmap(uiID));

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM