2 在我们的app中会有一个独立的photo Extension app 文件
刚进入界面的时候,我们能从这个获取到extnsion的对象和获取到图片对象,把获取的图片展示到背景图片上
- (void)startContentEditingWithInput:(PHContentEditingInput *)contentEditingInput placeholderImage:(UIImage *)placeholderImage { self.backGroundImageView.image = placeholderImage; CGSize newSize = [self getImageSizeFrame:placeholderImage]; self.backGroundImageView.frame = CGRectMake(0, 0, newSize.width, newSize.height); }
5 通过coreImage对图片进行编辑
那么如何实现改变图片的image的样式呢,我们通过coreImage的方式
<span style="white-space:pre"> </span>CIFilter * filter = [CIFilter filterWithName:@"CISepiaTone"]; [filter setValue:originalImage forKey:@"inputImage"]; [filter setValue:[NSNumber numberWithFloat:5] forKey:@"inputIntensity"]; CIContext *context = [CIContext contextWithOptions:[NSDictionary dictionary]]; CIImage * ciImage = [filter outputImage]; CGImageRef cgimg = [context createCGImage:ciImage fromRect:[ciImage extent]]; UIImage * image = [UIImage imageWithCGImage:cgimg scale:1.0f orientation:UIImageOrientationUp]; CGImageRelease(cgimg);
6 保存编辑的图谱到相册
- (void)finishContentEditingWithCompletionHandler:(void (^)(PHContentEditingOutput *))completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input]; NSData * archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.selectedFilterName]; PHAdjustmentData * adjuestmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.grandsoft.ReadBook" formatVersion:@"1.0" data:archivedData]; output.adjustmentData = adjuestmentData; switch (self.input.mediaType) { case PHAssetMediaTypeImage: { NSURL * url = self.input.fullSizeImageURL; int orie = self.input.fullSizeImageOrientation; UIImage * image = [UIImage imageWithContentsOfFile:url.path]; image = [self transformedImage:image withOrientation:orie usingFilter:self.ciFilter]; NSData * receJPEGData = UIImageJPEGRepresentation(image, 0.9); NSError * error = nil; BOOL success = [receJPEGData writeToURL:output.renderedContentURL options:NSDataWritingAtomic error:&error]; if(success) { completionHandler(output); } else { completionHandler(nil); } break; } case PHAssetMediaTypeVideo: { break; } default: break; } completionHandler(output); }); }
原文地址:http://blog.csdn.net/wjsxiaoweige/article/details/39524291