在 UIImage 上应用锐化滤镜时我遇到了一些问题。
该代码完美运行,但生成的 UIImage 具有 Alpha 通道的问题。这反过来会导致一些性能问题。
这就是我初始化上下文和过滤器的方式
EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
[options setObject: [NSNull null] forKey: kCIContextWorkingColorSpace];
context = [CIContext contextWithEAGLContext:myEAGLContext options:options];
sharpenLuminanceFilter = [CIFilter filterWithName:@"CISharpenLuminance"];
我使用以下函数生成图像
- (UIImage *)applySharpingFilter:(UIImage *)originalImage withValue:(float)value{
CIImage *image = [CIImage imageWithCGImage:originalImage.CGImage];
[sharpenLuminanceFilter setValue:image forKey:@"inputImage"];
[sharpenLuminanceFilter setValue:[NSNumber numberWithFloat:value] forKey:@"inputSharpness"];
CIImage * result = sharpenLuminanceFilter.outputImage;
CGImageRef cgimg = [context createCGImage:result fromRect:[result extent]];
double scaleFactor = [UIScreen mainScreen].scale;
UIImage *finalImage = [UIImage imageWithCGImage:cgimg scale:scaleFactor orientation:UIImageOrientationUp];
CGImageRelease(cgimg);
[sharpenLuminanceFilter setValue:nil forKey:@"inputImage"];
return finalImage;
}
无论如何我可以指定我希望生成的图像是不透明的并且没有 alpha 通道吗?