How can I generate a barcode from a string in Swift?

You could use a CoreImage (import CoreImage) filter to do that! class Barcode { class func fromString(string : String) -> UIImage? { let data = string.data(using: .ascii) if let filter = CIFilter(name: “CICode128BarcodeGenerator”) { filter.setValue(data, forKey: “inputMessage”) if let outputCIImage = filter.outputImage { return UIImage(ciImage: outputCIImage) } } return nil } } let img = … Read more

CIFilter output image nil

You cannot call UIImage(CIImage:) and use that UIImage as the image of a UIImageView. UIImageView requires a UIImage backed by a bitmap (CGImage). A UIImage instantiated with CIImage has no bitmap; it has no actual image, it’s just a set of instructions for applying a filter. That is why your UIImageView’s image is nil.

How to apply a Vignette CIFilter to a live camera feed in iOS?

Your step 2 is way too slow to support real-time rendering… and it looks like you’re missing a couple of steps. For your purpose, you would typically: Setup: create a pool of CVPixelBuffer – using CVPixelBufferPoolCreate create a pool of metal textures using CVMetalTextureCacheCreate For each frame: convert CMSampleBuffer > CVPixelBuffer > CIImage Pass that … Read more

Does iOS 5 support blur CoreImage fiters?

While Core Image on iOS 5.0 lacks blur filters, there is still a way to get GPU-accelerated blurs of images and video. My open source GPUImage framework has multiple blur types, including Gaussian (using the GPUImageGaussianBlurFilter for a general Gaussian or the GPUImageFastBlurFilter for a hardware-optimized 9-hit Gaussian), box (using a GPUImageBoxBlurFilter), median (using a … Read more

Why can’t I invert my image back to original with CIFilter in my Swift iOS app

The problem is this line: imageView.image = UIImage(CIImage: (filter.outputImage)!) You can’t do that. A CIImage does not magically turn into a UIImage. An image view needs a bitmap-based image, not a CIImage-based image. You have to render the CIImage to turn it into a UIImage, either by getting a CIContext and telling it to create … Read more

What is the best Core Image filter to produce black and white effects?

– (UIImage *)imageBlackAndWhite { CIImage *beginImage = [CIImage imageWithCGImage:self.CGImage]; CIImage *blackAndWhite = [CIFilter filterWithName:@”CIColorControls” keysAndValues:kCIInputImageKey, beginImage, @”inputBrightness”, [NSNumber numberWithFloat:0.0], @”inputContrast”, [NSNumber numberWithFloat:1.1], @”inputSaturation”, [NSNumber numberWithFloat:0.0], nil].outputImage; CIImage *output = [CIFilter filterWithName:@”CIExposureAdjust” keysAndValues:kCIInputImageKey, blackAndWhite, @”inputEV”, [NSNumber numberWithFloat:0.7], nil].outputImage; CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgiimage = [context createCGImage:output fromRect:output.extent]; //UIImage *newImage = [UIImage imageWithCGImage:cgiimage]; UIImage *newImage … Read more

Correct crop of CIGaussianBlur

Take the following code as an example… CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage = [[CIImage alloc] initWithImage:image]; CIFilter *filter = [CIFilter filterWithName:@”CIGaussianBlur”]; [filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:[NSNumber numberWithFloat:5.0f] forKey:@”inputRadius”]; CIImage *result = [filter valueForKey:kCIOutputImageKey]; CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]]; This results in the images you provided above. But if I instead use … Read more

Creating a blurring overlay view

You can use UIVisualEffectView to achieve this effect. This is a native API that has been fine-tuned for performance and great battery life, plus it’s easy to implement. Swift: //only apply the blur if the user hasn’t disabled transparency effects if !UIAccessibility.isReduceTransparencyEnabled { view.backgroundColor = .clear let blurEffect = UIBlurEffect(style: .dark) let blurEffectView = UIVisualEffectView(effect: … Read more