将图像叠加到另一个图像中

时间:2014-06-15 08:01:03

标签: ios iphone uiimagepickercontroller uigraphicscontext

我正在尝试用另一张图片覆盖图像。我试过了this但是,它并没有完全给出我期待的输出。让我通过下面的图片清楚地解释一下,

Image

上面是我的ViewController,我正在使用{{1}显示用于拍摄照片(Backgorund Image)的相机。我放置了叠加图像。我的叠加图像可以旋转并缩放:

UIImagePickerController

一旦拍摄完照片,我就会通过下面的代码将图像覆盖在拍摄的图像上:

if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos]) {
    cameraPicker = [[UIImagePickerController alloc] init];
    cameraPicker.delegate = self;
    cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
    [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
    cameraPicker.mediaTypes = mediaTypes;
    cameraPicker.showsCameraControls = NO;
    cameraPicker.navigationBarHidden = YES;
    cameraPicker.toolbarHidden = YES;
    cameraPicker.delegate = self;
    cameraPicker.allowsEditing = NO;

    [self presentViewController:cameraPicker animated:YES completion:^{
        overLayCustomView.hidden = NO;
        [cameraPicker.view addSubview:overLayCustomView];
    }];
}

scaleAndRotateImage的代码

当我尝试这些结果时,图像处理工作很奇怪。它给出了以下问题,

  • 拍摄的图像NSString *mediaType = info[UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { UIImage *image = [self scaleAndRotateImage:[info objectForKey:UIImagePickerControllerOriginalImage]]; UIGraphicsBeginImageContextWithOptions(image.size, FALSE, 0.0); [image drawInRect:CGRectMake( 0, 0, image.size.width, image.size.height)]; [renderedImage.image drawInRect:CGRectMake( renderedImage.frame.origin.x, renderedImage.frame.origin.y, renderedImage.frame.size.width, renderedImage.frame.size.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil); UIGraphicsEndImageContext(); [picker dismissViewControllerAnimated:YES completion:^{ [self performSegueWithIdentifier:@"previewPage" sender:newImage]; }]; } else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) { // Code here to support video if enabled } 清晰度已丢失。
  • 叠加图像未放置框架的确切位置。
  • 叠加图像的帧改变,如果旋转未被捕获为旋转图像。

是否有关于我的代码简要解释的想法?


更新

是的,最后,我已经实现了这一点并使用(Background Image)捕获图片而不是使用AVCaptureSession这将是一个有用的。现在,唯一的事情是,我的叠加图像可以旋转到一个以下,

UIImagePickerController

我无法将旋转的叠加图像叠加到另一张图像中。无法获得旋转的图像?我怎样才能做到这一点?

0 个答案:

没有答案