9
我想在iOS 6上使用CoreImage模糊圖像,而沒有明顯的黑色邊框。 Apple documentation指出使用CIAffineClamp過濾器可以實現這一點,但我無法從過濾器獲取輸出圖像。這是我嘗試過的,但不幸的是,當我訪問[clampFilter outputImage]時會創建一個空的圖像。如果我僅執行模糊處理,則會生成圖像,但是會使用黑色插入邊框。iOS 6上的CIGaussianBlur和CIAffineClamp 6
CIImage *inputImage = [[CIImage alloc] initWithCGImage:self.CGImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGAffineTransform transform = CGAffineTransformIdentity;
CIFilter *clampFilter = [CIFilter filterWithName:@"CIAffineClamp"];
[clampFilter setValue:inputImage forKey:kCIInputImageKey];
[clampFilter setValue:[NSValue valueWithBytes:&transform objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"];
CIImage *outputImage = [clampFilter outputImage];
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"
keysAndValues:kCIInputImageKey, outputImage, @"inputRadius", [NSNumber numberWithFloat:radius], nil];
outputImage = [blurFilter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *blurredImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
contextRect是個問題。我實際上通過在最後創建CGImage時更改此行以使用inputImage範圍來修復它: 'CGImageRef cgimg = [context createCGImage:outputImage fromRect:inputImage.extent];' – bryguy1300