iOS开发-每日一记—照片滤镜App

1,选择照片,拍照

_imagePickerController = [[UIImagePickerController alloc] init];

_imagePickerController.delegate = self;

_imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

_imagePickerController.allowsEditing = YES

sourceType和mediaTypes 设置打开摄像头还是图片库,获取media类型。

2,展示照片和可以滚动的滤镜选项。

UIimageView + UiCollectionView

UIimageView contentMode    =  UIViewContentModeScaleAspectFit;

//设置collectionView横向滚动

UICollectionViewFlowLayout *layout =  [[UICollectionViewFlowLayout alloc]init];[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

//把图片转为有滤镜的照片

CIImage *outPutImage =  [[CIImage alloc]initWithImage:image];

CIFilter  *_fitler  =  [CIFilter filterWithName:Model.fitlerName];

if (_fitler!=nil) {

[_fitler setValue:outPutImage forKey:kCIInputImageKey];

outPutImage =  _fitler.outputImage;

}

CGImageRef  imageRef    =  [[self context] createCGImage:outPutImage fromRect:outPutImage.extent];

self.fitlerImage.image  =  [[UIImage alloc]initWithCGImage:imageRef scale:1.0 orientation:UIImageOrientationUp];

CGImageRelease(imageRef);

cicontext 用来渲染

EAGLContext    *eaglContext    =  [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES2];

context =  [CIContext contextWithEAGLContext:eaglContext options:nil];


3.选择滤镜更改照片

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

FitlerCollectionViewCell    *cell  =  (FitlerCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];

self.fitlerImageView.image  =  cell.fitlerImage.image;

}

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

推荐阅读更多精彩内容