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;
}