我正在开发一个视频会议应用程序,以下代码成功地在屏幕上绘制了一个框架:
-(int)drawFrameOnMainThread{
if(mBitmapContext){
if(mDisplay){
CGImageRef imageRef = CGBitmapContextCreateImage(mBitmapContext);
#if TARGET_OS_IPHONE
UIImage *image = [UIImage imageWithCGImage:imageRef];
[self performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
#elif TARGET_OS_MAC
[mDisplay setCurrentImage:imageRef];
#endif
CGImageRelease(imageRef);
}
}
return 0;
}
我想将 CIFilter 应用于正在绘制的框架,所以我修改了代码的 iOS 部分,如下所示:
UIImage *image = [UIImage imageWithCGImage:imageRef];
CIImage *beginImage = image.CIImage;
CIContext *context = [CIContext contextWithOptions:nil];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"
keysAndValues: kCIInputImageKey, beginImage,
@"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg =
[context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
[self performSelectorOnMainThread:@selector(setImage:) withObject:newImg waitUntilDone:YES];
结果是我的视频屏幕保持黑色。任何人都可以在这里看到错误吗?我已经在这几个小时了,但无法弄清楚。