iOS CoreImage學習之高斯模糊效果
筆者進入IT技術領域(不只是iOS哦)不太久,需要學習的東西還很多,因此將自己學習時用到的知識整理出來,供大家閑暇時間參考批評。
//獲取需要濾鏡的圖片資源。
CIImage *ciimage = [[CIImage alloc]
initWithCGImage:[UIImageimageNamed:@"05B2F0B2D527724E2D01E6223AEE6B5D"].CGImage];
//獲取濾鏡 使用filterWithName 指定哪種濾鏡效果。--具體名字 百度
CIFilter *filter = [CIFilterfilterWithName:@"CIGaussianBlur"];
Advertisements
NSLog(@"%@",filter.attributes);
//將圖片輸入到濾鏡中,打個比方:濾鏡是個具有某個功能的容器,任何東西放進去,拿出來的時候就會附上效果。
//將圖片輸入到濾鏡中
[filter setValue:ciimage forKey:kCIInputImageKey];
//從濾鏡容器中取出圖片 這裡還有一種輸出方式:使用CIcontext 不知道這兩種有什麼優缺點,歡迎留言
CIImage *new = [filter valueForKey:kCIOutputImageKey];
UIImageView *ima = [[UIImageView alloc]initWithFrame:self.view.frame];
Advertisements
//CPU渲染
CIContext *context = [CIContext contextWithOptions:nil];
//獲取添加濾鏡后的CGImageRef ,大小為本身的frame
CGImageRef image = [context createCGImage:new fromRect:[newextent]];
//釋放內存
CGImageRelease(image);
ima.image = [UIImage imageWithCGImage:image];
得到結果:
還可以通過
NSLog(@"%@",filter.attributes);
對過濾器的屬性進行列印,對其中某個屬性進行設置
[filter setValue:@(100)forKey:@"inputRadius"];
結果如下: