diff --git a/modules/imgcodecs/src/apple_conversions.h b/modules/imgcodecs/src/apple_conversions.h index c68b922cfb..65d3a7e08b 100644 --- a/modules/imgcodecs/src/apple_conversions.h +++ b/modules/imgcodecs/src/apple_conversions.h @@ -2,10 +2,27 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. +#ifndef OPENCV_IMGCODECS_APPLE_CONVERSIONS_H +#define OPENCV_IMGCODECS_APPLE_CONVERSIONS_H + #include "opencv2/core.hpp" #import + +#include + +#ifdef HAVE_AVFOUNDATION #import +#endif + +#if TARGET_OS_IPHONE || (defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080) #import +#else +#import +#import +#import +#endif CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED; CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist); + +#endif // OPENCV_IMGCODECS_APPLE_CONVERSIONS_H \ No newline at end of file diff --git a/modules/imgcodecs/src/apple_conversions.mm b/modules/imgcodecs/src/apple_conversions.mm index 6126039ce0..6b1834504b 100644 --- a/modules/imgcodecs/src/apple_conversions.mm +++ b/modules/imgcodecs/src/apple_conversions.mm @@ -5,6 +5,12 @@ #include "apple_conversions.h" #include "precomp.hpp" +#import + +#ifndef __bridge +#define __bridge +#endif + CGImageRef MatToCGImage(const cv::Mat& image) { NSData *data = [NSData dataWithBytes:image.data length:image.step.p[0] * image.rows]; diff --git a/modules/imgcodecs/src/macosx_conversions.mm b/modules/imgcodecs/src/macosx_conversions.mm index 0023e06260..960139e2f1 100644 --- a/modules/imgcodecs/src/macosx_conversions.mm +++ b/modules/imgcodecs/src/macosx_conversions.mm @@ -13,9 +13,11 @@ NSImage* MatToNSImage(const cv::Mat& image) { CGImageRef imageRef = MatToCGImage(image); // Getting NSImage from CGImage - NSImage *nsImage = [[NSImage alloc] initWithCGImage:imageRef size:CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef))]; + NSSize imageSize = NSMakeSize(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)); + NSImage *nsImage = [[NSImage alloc] initWithCGImage:imageRef size:imageSize]; CGImageRelease(imageRef); + return nsImage; }