[英]QImage from HBITMAP
在我的仅限Windows的程序中,我使用第三方库,它返回HBITMAP
。
有没有办法从其内容初始化QImage
,即将其转换为QImage
?
这是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)
好的,这似乎对我有用:
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));
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.