iOS濾鏡簡單demo

NSURL *iamgeUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"default" ofType:@"png"]];
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *image = [CIImage imageWithContentsOfURL:iamgeUrl];
    
    CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"];
    [filter setValue:image forKey:kCIInputImageKey];
    [filter setValue:[NSNumber numberWithFloat:0.5] forKey: @"inputIntensity"];
    
    CIImage *result = [filter valueForKey:kCIOutputImageKey];
    CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];
    UIImage * blurImage = [UIImage imageWithCGImage:outImage];
    _imageBG = [[UIImageView alloc] initWithImage:blurImage];
    _imageBG.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    
    [self.view addSubview:self.imageBG];



CIImage 保存圖像數據的類,可以通過UIImage,圖像文件或者像素數據來創建。

CIFilter 濾鏡類,這個框架中對圖片屬性進行細節處理的類。它對所有的像素進行操作,用一些鍵-值設置來決定具體操作的程度。

CIContext 上下文類,如CoreGraphics以及CoreData中的上下文用於處理繪製渲染以及處理託管對象一樣,CoreImage的上下文也是實現對圖像處理的具體對象。


打印所有的濾鏡信息:

//打印所有過濾器信息
    NSArray *properties = [CIFilter filterNamesInCategory:kCICategoryBuiltIn];
    NSLog(@"FilterName:\n%@", properties);
    for (NSString *filterName in properties) {
        CIFilter *fltr = [CIFilter filterWithName:filterName];
        NSLog(@"%@:\n%@", filterName, [fltr attributes]);
    }




    


發佈了88 篇原創文章 · 獲贊 18 · 訪問量 51萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章