我有一些問題應用過濾器的圖像。使用CIImage時,下面的代碼工作完美:imageWithContentsOfURL:來自NSURL的CGImage工作,但不是從UIImage
NSInteger filterIndex = [(UITapGestureRecognizer *)sender view].tag;
Filter *filter = [filters objectAtIndex:filterIndex];
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *image = [CIImage imageWithContentsOfURL:[NSURL URLWithString:@"http://url.to/photo.jpg"]];
[filter.filter setValue:image forKey:kCIInputImageKey];
CIImage *result = [filter.filter valueForKey:kCIOutputImageKey];
CGRect extent = [result extent];
CGImageRef cgImage = [context createCGImage:result fromRect:extent];
[self.imageView setImage:[UIImage imageWithCGImage:cgImage]];
過濾器只是一個模型控股過濾器名稱和CIFilter:
-(id)initWithNameAndFilter:(NSString *)theName filter:(CIFilter *)theFilter;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) CIFilter *filter;
但是當我嘗試加載與下面的代碼在本地的UIImage:
CIImage *ciImage = [UIImage imageNamed:@"test.png"].CIImage;
已過濾的圖像只變白(或消失)。我究竟做錯了什麼?