diff options
-rw-r--r-- | src/winextras/qwinfunctions.cpp | 31 | ||||
-rw-r--r-- | src/winextras/qwinfunctions.h | 2 | ||||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 18 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/winextras/qwinfunctions.cpp b/src/winextras/qwinfunctions.cpp index 7b102a8..7089966 100644 --- a/src/winextras/qwinfunctions.cpp +++ b/src/winextras/qwinfunctions.cpp @@ -69,6 +69,8 @@ Q_GUI_EXPORT HBITMAP qt_createIconMask(const QBitmap &bitmap); Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0); Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0); Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &p); +Q_GUI_EXPORT HBITMAP qt_imageToWinHBITMAP(const QImage &imageIn, int hbitmapFormat = 0); +Q_GUI_EXPORT QImage qt_imageFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0); Q_GUI_EXPORT QImage qt_imageFromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h); Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon); @@ -139,6 +141,22 @@ HICON QtWin::toHICON(const QPixmap &p) } /*! + \since 5.12 + + Creates a \c HBITMAP equivalent of the QImage \a image, + based on the given \a format. Returns the \c HBITMAP handle. + + It is the caller's responsibility to free the \c HBITMAP data + after use. + + \sa imageFromHBITMAP() +*/ +HBITMAP QtWin::imageToHBITMAP(const QImage &image, QtWin::HBitmapFormat format) +{ + return qt_imageToWinHBITMAP(image, format); +} + +/*! \since 5.2 Returns a QImage that is equivalent to the @@ -153,6 +171,19 @@ QImage QtWin::imageFromHBITMAP(HDC hdc, HBITMAP bitmap, int width, int height) } /*! + \since 5.12 + + Returns a QImage that is equivalent to the + given \a bitmap. The conversion is based on the specified \a format. + + \sa imageToHBITMAP() +*/ +QImage QtWin::imageFromHBITMAP(HBITMAP bitmap, QtWin::HBitmapFormat format) +{ + return qt_imageFromWinHBITMAP(bitmap, format); +} + +/*! \since 5.2 Returns a QPixmap that is equivalent to the given \a icon. diff --git a/src/winextras/qwinfunctions.h b/src/winextras/qwinfunctions.h index bc07401..fe461d1 100644 --- a/src/winextras/qwinfunctions.h +++ b/src/winextras/qwinfunctions.h @@ -81,7 +81,9 @@ namespace QtWin Q_WINEXTRAS_EXPORT HBITMAP toHBITMAP(const QPixmap &p, HBitmapFormat format = HBitmapNoAlpha); Q_WINEXTRAS_EXPORT QPixmap fromHBITMAP(HBITMAP bitmap, HBitmapFormat format = HBitmapNoAlpha); Q_WINEXTRAS_EXPORT HICON toHICON(const QPixmap &p); + Q_WINEXTRAS_EXPORT HBITMAP imageToHBITMAP(const QImage &image, QtWin::HBitmapFormat format = HBitmapNoAlpha); Q_WINEXTRAS_EXPORT QImage imageFromHBITMAP(HDC hdc, HBITMAP bitmap, int width, int height); + Q_WINEXTRAS_EXPORT QImage imageFromHBITMAP(HBITMAP bitmap, QtWin::HBitmapFormat format = HBitmapNoAlpha); Q_WINEXTRAS_EXPORT QPixmap fromHICON(HICON icon); Q_WINEXTRAS_EXPORT HRGN toHRGN(const QRegion ®ion); Q_WINEXTRAS_EXPORT QRegion fromHRGN(HRGN hrgn); diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 8a63e25..8383194 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -29,6 +29,7 @@ #include <QtTest/QtTest> #include <QtCore/qt_windows.h> #include <QtCore/QFileInfo> +#include <QtGui/QPainter> #include <QtGui/QPixmap> #include <QtGui/QImage> #include <QtWinExtras/QtWin> @@ -53,6 +54,8 @@ private slots: void fromHICON_data(); void fromHICON(); + void imageConversion(); + private: const QString m_dataDirectory; }; @@ -279,6 +282,21 @@ void tst_QPixmap::fromHICON() QVERIFY2(compareImages(imageFromHICON, imageFromFile, &errorMessage), errorMessage.constData()); } +void tst_QPixmap::imageConversion() +{ + // Extensive testing of all formats is done in QtGui; this merely tests + // the exports/linkage. + QImage image(73, 57, QImage::Format_ARGB32_Premultiplied); + image.fill(Qt::red); + QPainter painter(&image); + painter.drawLine(0, 0, image.width(), image.height()); + const HBITMAP hBitMap = QtWin::imageToHBITMAP(image); + QVERIFY(hBitMap); + const QImage fromHBitMap = QtWin::imageFromHBITMAP(hBitMap, QtWin::HBitmapPremultipliedAlpha); + QCOMPARE(fromHBitMap, image); + DeleteObject(hBitMap); +} + QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" |