GPUImage 将绿色背景变透明背景

使用GPUImage 的 GPUImageChromaKeyBlendFilter 将绿色背景替换为透明背景。

代码

    // 准备一张透明的图片
    UIImage *transparentImg= [UIImage imageNamed:@"MTransparent"];
    
    // 待处理的图片
    UIImage *inputImage = [UIImage imageNamed:@"input"];
    GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
    
    // 创建Filter
    GPUImageChromaKeyBlendFilter *filter = [[GPUImageChromaKeyBlendFilter alloc] init];
    [filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
    [pic addTarget:filter];
    [pic processImage];
    
    // 原始图片
    UIImageView *inputImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 200, 100, 100)];
    inputImageView.image = inputImage;
    [self.view addSubview:inputImageView];
    
    // 创建UIImageView 用于呈现结果
    UIImageView *resultImageView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
    resultImageView.image = [filter imageByFilteringImage:transparentImg];
    [self.view addSubview:resultImageView];

input.png

input.png

效果

image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,245评论 4 61
  • 1. 最近公司忙于招聘事宜,我也算过了一把HR的瘾。 每天忙于穿梭在各种报表对账中,抽空查看简历约见面试,并且初试...
    嗨七爷阅读 385评论 4 3
  • 作为淡香水留香时间不会很长大概7小时左右,正如香评家Tania Sanchez所说名字邪恶出身平凡,实际上是名字误...
    Moondea阅读 5,903评论 0 1
  • 三月,我设了一个闹钟,早上六点起床,然后具体怎样学习生活都写了一大堆,我想为了可以更好的把握时间,管理自己作出一定...
    翎馨阅读 648评论 0 0