diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-11-16 17:10:50 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-11-17 07:05:14 +0100 |
commit | 4373c4436abf6636821489cdd79cffb3e4be5359 (patch) | |
tree | d5423d89b2016a090621d1fc943d205dfa027ce5 /src/gui/painting | |
parent | 54656da9ace06caf4a0eeb1832989c0ab211a4a0 (diff) |
iOS: add helper to convert UIImage to QImage
Going through the UIImage.CGImage flattens the image to monochrome.
Change-Id: If74c33badb4e94253b3bf21b6d69bb9f521d6bff
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qcoregraphics.mm | 18 | ||||
-rw-r--r-- | src/gui/painting/qcoregraphics_p.h | 15 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm index c05ba06146..e8904dff06 100644 --- a/src/gui/painting/qcoregraphics.mm +++ b/src/gui/painting/qcoregraphics.mm @@ -182,6 +182,24 @@ QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size) #endif // Q_OS_MACOS +#ifdef Q_OS_IOS + +QImage qt_mac_toQImage(const UIImage *image, QSizeF size) +{ + QImage ret(size.width(), size.height(), QImage::Format_ARGB32_Premultiplied); + ret.fill(Qt::transparent); + QMacCGContext ctx(&ret); + if (!ctx) + return QImage(); + UIGraphicsPushContext(ctx); + const CGRect rect = CGRectMake(0, 0, size.width(), size.height()); + [image drawInRect:rect]; + UIGraphicsPopContext(); + return ret; +} + +#endif // Q_OS_IOS + // ---------------------- Colors and Brushes ---------------------- QColor qt_mac_toQColor(CGColorRef color) diff --git a/src/gui/painting/qcoregraphics_p.h b/src/gui/painting/qcoregraphics_p.h index f0640ba500..f2c2ba1db1 100644 --- a/src/gui/painting/qcoregraphics_p.h +++ b/src/gui/painting/qcoregraphics_p.h @@ -23,15 +23,24 @@ #include <CoreGraphics/CoreGraphics.h> -#if defined(__OBJC__) && defined(Q_OS_MACOS) -#include <AppKit/AppKit.h> -#define HAVE_APPKIT +#if defined(__OBJC__) +# if defined(Q_OS_MACOS) +# include <AppKit/AppKit.h> +# define HAVE_APPKIT +# elif defined(Q_OS_IOS) +# include <UIKit/UIKit.h> +# define HAVE_UIKIT +# endif #endif QT_BEGIN_NAMESPACE Q_GUI_EXPORT CGBitmapInfo qt_mac_bitmapInfoForImage(const QImage &image); +#ifdef HAVE_UIKIT +Q_GUI_EXPORT QImage qt_mac_toQImage(const UIImage *image, QSizeF size); +#endif + #ifdef HAVE_APPKIT Q_GUI_EXPORT QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size); |