GPUImage使用
2016-01-06 17:44
1066 查看
GIit: https://github.com/BradLarson/GPUImage/downloads
如下
图像处理
1.打开Framework中GPUImage.xcodeproj,运行项目 2.在targets->build Rules中拷贝头文件 3.运行项目后将products中.a文件和头文件放一起加入工程
如下
图像处理
UIImage* imageOri =[self processUsingGPUImage: [UIImage imageNamed:@"960.png"]]; UIImageView *imageOriView = [[UIImageView alloc]initWithFrame:self.view.frame]; imageOriView.image = imageOri; [self.view addSubview:imageOriView]; //曝光 GPUImageExposureFilter *passthroughFilter2 = [[GPUImageExposureFilter alloc]init]; passthroughFilter2.exposure = 2; [passthroughFilter2 forceProcessingAtSize:imageOri.size]; GPUImagePicture *stillImageSource2 = [[GPUImagePicture alloc]initWithImage:imageOri]; [stillImageSource2 addTarget:passthroughFilter2]; [stillImageSource2 processImage]; UIImage *nearestNeighborImage2 = [UIImage imageWithCGImage:[passthroughFilter2 newCGImageFromCurrentlyProcessedOutput]] ; UIImageView *imageView2 = [[UIImageView alloc]initWithImage:nearestNeighborImage2]; imageView2.frame = CGRectMake(5, 120, 150, 90); [self.view addSubview:imageView2]; GPUImageHueFilter *passthroughFilter3 = [[GPUImageHueFilter alloc]init]; passthroughFilter3.hue = 20; [passthroughFilter3 forceProcessingAtSize:imageOri.size]; GPUImagePicture *stillImageSource3 = [[GPUImagePicture alloc]initWithImage:imageOri]; [stillImageSource3 addTarget:passthroughFilter3]; [stillImageSource3 processImage]; UIImage *nearestNeighborImage3 = [UIImage imageWithCGImage:[passthroughFilter3 newCGImageFromCurrentlyProcessedOutput]]; UIImageView *imageView3 = [[UIImageView alloc]initWithImage:nearestNeighborImage3]; imageView3.frame = CGRectMake(0, 0, 150, 200); [self.view addSubview:imageView3]; - (UIImage *)processUsingGPUImage:(UIImage*)input { // 1. Create the GPUImagePictures GPUImagePicture * inputGPUImage = [[GPUImagePicture alloc] initWithImage:input]; UIImage * ghostImage = [self createPaddedGhostImageWithSize:input.size]; GPUImagePicture * ghostGPUImage = [[GPUImagePicture alloc] initWithImage:ghostImage]; // 2. Set up the filter chain GPUImageAlphaBlendFilter * alphaBlendFilter = [[GPUImageAlphaBlendFilter alloc] init]; alphaBlendFilter.mix = 0.5; [inputGPUImage addTarget:alphaBlendFilter atTextureLocation:0]; [ghostGPUImage addTarget:alphaBlendFilter atTextureLocation:1]; GPUImageGrayscaleFilter * grayscaleFilter = [[GPUImageGrayscaleFilter alloc] init]; [alphaBlendFilter addTarget:grayscaleFilter]; // 3. Process & grab output image [grayscaleFilter useNextFrameForImageCapture]; [inputGPUImage processImage]; [ghostGPUImage processImage]; UIImage * output = [grayscaleFilter imageFromCurrentFramebuffer]; return output; } - (UIImage *)createPaddedGhostImageWithSize:(CGSize)inputSize { UIImage * ghostImage = [UIImage imageNamed:@"960.png"]; CGFloat ghostImageAspectRatio = ghostImage.size.width / ghostImage.size.height; NSInteger targetGhostWidth = inputSize.width * 0.25; CGSize ghostSize = CGSizeMake(targetGhostWidth, targetGhostWidth / ghostImageAspectRatio); CGPoint ghostOrigin = CGPointMake(inputSize.width * 0.5, inputSize.height * 0.2); CGRect ghostRect = {ghostOrigin, ghostSize}; UIGraphicsBeginImageContext(inputSize); CGContextRef context = UIGraphicsGetCurrentContext(); CGRect inputRect = {CGPointZero, inputSize}; CGContextClearRect(context, inputRect); CGAffineTransform flip = CGAffineTransformMakeScale(1.0, -1.0); CGAffineTransform flipThenShift = CGAffineTransformTranslate(flip,0,-inputSize.height); CGContextConcatCTM(context, flipThenShift); CGRect transformedGhostRect = CGRectApplyAffineTransform(ghostRect, flipThenShift); CGContextDrawImage(context, transformedGhostRect, [ghostImage CGImage]); UIImage * paddedGhost = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return paddedGhost; }
相关文章推荐
- UIFileSharingEnabled开启而App仍然无法共享文件
- 3、IOS开发--iPad之仿制QQ空间 (为HomeViewController添加交互逻辑 并 为导航条内容添加UISegmentedControl)
- iOS UITableView(九) 给tableView添加索引
- 获取UIImage中的图像数据
- UITableView中visibleCells方法的使用
- IOS将UIView转化为UIImage
- [UE4]UMG、HUI、Slate之间的区别
- ios9新特性UIStackView
- LinkedBlockingQueue
- ueditor表格边框没有颜色的解决
- FlatBuffers文档-Building
- 【iOS开发】关于显示一连串图片组成动画效果UIImageView的使用
- BlockingQueue!
- UILabel 的使用,属性详解
- [bug] Field 'id' doesn't have a default value
- UITableView - 重用机制
- mysql DECLARE CONTINUE HANDLER FOR NOT FOUND
- 13 UIGestureRecognizer and UIMenuController
- MySQL SQL优化案例:相关子查询(dependent subquery)优化
- Android 之UI自适应解决方案