【发布时间】:2013-01-28 18:24:41
【问题描述】:
在我的纯 Windows 程序中,我使用第三方库,它返回 HBITMAP。
有没有办法从 QImage 的内容中初始化它,即将其转换为 QImage?
【问题讨论】:
标签: c++ qt qimage qtgui hbitmap
在我的纯 Windows 程序中,我使用第三方库,它返回 HBITMAP。
有没有办法从 QImage 的内容中初始化它,即将其转换为 QImage?
【问题讨论】:
标签: c++ qt qimage qtgui hbitmap
这是 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)
【讨论】:
fromWinHBITMAP 现在是 QImage 的一部分,因此您只需调用 QImage.fromHBITMAP。
好的,这似乎对我有用:
QImage image(QPixmap::fromWinHBITMAP(hBitmap).toImage());
【讨论】:
没有附加功能的 Qt5: 放在你的代码之前
#include <QPixmap>
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat=0);
在你的函数中,例如
QPixmap pixmap = qt_pixmapFromWinHBITMAP(LoadBitmap(uiID));
干杯
【讨论】: