//獲取需要濾鏡的圖片資源。
CIImage *ciimage = [[CIImage alloc]
initWithCGImage:[UIImage imageNamed:@"05B2F0B2D527724E2D01E6223AEE6B5D"].CGImage];
//獲取濾鏡 使用filterWithName 指定哪種濾鏡效果。--具體名字 百度
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
NSLog(@"%@",filter.attributes);
//將圖片輸入到濾鏡中,打個比方:濾鏡是個具有某個功能的容器,任何東西放進去,拿出來的時候就會附上效果。
//將圖片輸入到濾鏡中
[filter setValue:ciimage forKey:kCIInputImageKey];
//從濾鏡容器中取出圖片 這裏還有一種輸出方式:使用CIcontext 不知道這兩種有什麼優缺點,歡迎留言
CIImage *new = [filter valueForKey:kCIOutputImageKey];
UIImageView *ima = [[UIImageView alloc] initWithFrame:self.view.frame];
/*
通過option 可以指定使用歐冠CPU 還是GPU渲染<pre name="code" class="objc">//CIContext *context = [CIContext contextWithOptions:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:kCI//ContextUseSoftwareRenderer]];//CPU渲染
CIContext *context = [CIContext contextWithOptions:nil]; //獲取添加濾鏡後的CGImageRef ,大小爲本身的frame CGImageRef image = [context createCGImage:new fromRect:[new extent]];
//釋放內存
CGImageRelease(image);
ima.image = [UIImage imageWithCGImage:image]; */ ima.image = [UIImage imageWithCIImage:new]; [self.view addSubview:ima];
還可以通過
NSLog(@"%@",filter.attributes);
得到下列信息
因此知道,可以對inputRadius的值進行修改。
[filter setValue:@(100)forKey:@"inputRadius"];
便得到以上效果!
蘇州iOS/Android技術討論羣:419277786