使用PhotoEditing扩展来对图像产生影响

时间:2015-01-06 13:00:39

标签: ios objective-c iphone ipad ios-extensions

我想在PhotoEditing Extension

中设置裁剪的图像

我提供了用于裁剪和旋转设施的设施,现在我想对模拟器的照片

产生影响
// Adjustment data
PHContentEditingOutput *contentEditingOutput = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input];

NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.strSelectedFilterName];

PHAdjustmentData *adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.test.PhotoEditingExtensionDemo"
                                                                        formatVersion:@"1.0"
                                                                                 data:archivedData];
contentEditingOutput.adjustmentData = adjustmentData;

switch (self.input.mediaType)
{
    case PHAssetMediaTypeImage:
    {
        // Get full size image
        NSURL *url = self.input.fullSizeImageURL;
        int orientation = self.input.fullSizeImageOrientation;

        // Generate rendered JPEG data
        UIImage *image = [UIImage imageWithContentsOfFile:url.path];
        image = [self transformedImage:image withOrientation:orientation usingFilter:self.ciFilter];
        NSData *renderedJPEGData = UIImageJPEGRepresentation(image, 0.9f);

        // Save JPEG data
        NSError *error = nil;
        BOOL success = [renderedJPEGData writeToURL:contentEditingOutput.renderedContentURL options:NSDataWritingAtomic error:&error];
        if (success) {
            completionHandler(contentEditingOutput);
        } else {
            NSLog(@"An error occured: %@", error);
            completionHandler(nil);
        }
        break;
    }

    case PHAssetMediaTypeVideo: {
        // Get AV asset
        AAPLAVReaderWriter *avReaderWriter = [[AAPLAVReaderWriter alloc] initWithAsset:self.input.avAsset];
        avReaderWriter.delegate = self;

        // Save filtered video
        [avReaderWriter writeToURL:contentEditingOutput.renderedContentURL
                          progress:^(float progress) {
                          }
                        completion:^(NSError *error) {
                            if (!error) {
                                completionHandler(contentEditingOutput);
                            } else {
                                NSLog(@"An error occured: %@", error);
                                completionHandler(nil);
                            }
                        }];
        break;
    }
    default:
        break;
}

0 个答案:

没有答案