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