I used this to generate a big image:
let context = CIContext(options: nil)
let bitmapImage: CGImageRef = context.createCGImage(image, fromRect: extent)!
CGContextSetInterpolationQuality(bitmapRef, CGInterpolationQuality.None)
CGContextScaleCTM(bitmapRef, scale, scale);
CGContextDrawImage(bitmapRef, extent, bitmapImage);
let scaledImage: CGImageRef = CGBitmapContextCreateImage(bitmapRef)!
return UIImage(CGImage: scaledImage)
It worked well in iOS 9 and 10 but not 8. I got this in the debugger:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x7f868d5dc8e0'
In addition. I tried to use let context = CIContext()
instead. But I got nil in the second line. I'm using Xcode 8 and Swift 2.3. Please help me with this! Thanks!
I have no idea if this will work, but we should try it: let's write that line in Objective-C. So:
#import <Foundation/Foundation.h>
#import <CoreImage/CoreImage.h>
@interface ContextMaker : NSObject
+ (CIContext*) makeMeAContext;
@end
#import "ContextMaker.h"
@implementation ContextMaker
+ (CIContext*) makeMeAContext {
return [CIContext contextWithOptions:nil];
}
@end
#import "ContextMaker.h"
let c = ContextMaker.makeMeAContext()
It will only take you a moment to try it, so give it a go and see if we can get past that troublesome line...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With