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>bb10
parent
54656da9ac
commit
4373c4436a
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue