HTCoreImage 1.0.1

HTCoreImage 1.0.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

未被认领 维护。



  • 作者:
  • Jacob Jennings

HTCoreImage 是 Core Image 方便类别的集合。每个滤镜都有一个方便的构造器,并使用 NS_AVAILABLE_SINCE() 宏进行了注释,以便您知道 iOS 5 和 iOS 6 中的内容。

示例:让我们增加图片的对比度并将其着色为蓝色

    UIImage *sourceUIImage = [UIImage imageNamed:@"asdf"];

    [[[sourceUIImage toCIImage] imageByApplyingFilters:@[
      [CIFilter filterColorControlsSaturation:1 brightness:1 contrast:2],
      [CIFilter filterColorMatrixWithRed:0.5 green:0.5 blue:1 alpha:1]]]
     processToUIImageCompletion:^(UIImage *uiImage) {
        NSLog(@"%@", uiImage);
    }];

以下是与库存 Core Image 相比较的相同内容

    UIImage *sourceUIImage = [UIImage imageNamed:@"asdf"];

    CIImage *sourceCIImage = [CIImage imageWithCGImage:sourceUIImage.CGImage];

    CIFilter *colorControlsFilter = [CIFilter filterWithName:@"CIColorControls"];
    [colorControlsFilter setDefaults];
    [colorControlsFilter setValue:@(1) forKey:@"inputSaturation"];
    [colorControlsFilter setValue:@(1) forKey:@"inputBrightness"];
    [colorControlsFilter setValue:@(2) forKey:@"inputContrast"];
    [colorControlsFilter setInputCIImage:sourceCIImage];

    CIFilter *colorMatrixFilter = [CIFilter filterWithName:@"CIColorMatrix"];
    [colorMatrixFilter setDefaults];
    [colorMatrixFilter setValue:[CIVector vectorWithX:0.5 Y:0 Z:0 W:0]
                         forKey:@"inputRVector"];
    [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0.5 Z:0 W:0]
                         forKey:@"inputGVector"];
    [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:1 W:0]
                         forKey:@"inputBVector"];
    [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:1]
                         forKey:@"inputAVector"];
    [colorMatrixFilter setInputCIImage:[colorControlsFilter outputImage]];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
                   {
                       CIContext *ciContext = [CIContext contextWithOptions:@{ kCIContextUseSoftwareRenderer : (id)kCFBooleanFalse }];
                       CGImageRef resultCGImage = [ciContext createCGImage:[colorMatrixFilter outputImage] fromRect:[[colorMatrixFilter outputImage] extent]];
                       UIImage *resultUIImage = [UIImage imageWithCGImage:resultCGImage scale:sourceUIImage.scale orientation:sourceUIImage.imageOrientation];
                       CGImageRelease(resultCGImage);
                       dispatch_async(dispatch_get_main_queue(), ^
                                      {
                                          NSLog(@"%@", resultUIImage);
                                      });
                   });

安装

推荐安装方法为 Cocoapods。将此行添加到您的 Podfile

pod 'HTCoreImage'

https://cocoapods.org.cn

欢迎贡献!

使用它?喜欢/讨厌它?

向作者 @jakejennings 发推特,并查看 HotelTonight 的工程博客:http://engineering.hoteltonight.com

此外,请查看 HotelTonight 的其他 iOS 开源项目