来自HBITMAP的QImage

时间:2013-01-28 18:24:42

标签: c++ qt qimage qtgui hbitmap

在我的仅限Windows的程序中,我使用第三方库,该库返回HBITMAP

有没有办法从其内容初始化QImage,即将其转换为QImage

3 个答案:

答案 0 :(得分:9)

这是Qt 4(QtGui)的方法:

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

这是为Qt 5(QtWinExtras)执行此操作的方法:

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

// or

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

答案 1 :(得分:2)

好的,这似乎对我有用:

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

答案 2 :(得分:0)

没有额外的Qt5: 放在你的代码之前

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

并在您的函数中,例如

QPixmap pixmap = qt_pixmapFromWinHBITMAP(LoadBitmap(uiID));

干杯