2

我想在 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;
}
4

0 回答 0