在相机视图中使用叠加保存图像

时间:2014-07-23 10:00:53

标签: ios iphone objective-c ios5

我使用以下代码在相机视图上添加了叠加层

- (IBAction)takephoto:(id)sender {

    mediaPicker = [[UIImagePickerController alloc] init];
    mediaPicker.delegate=self;
    mediaPicker.allowsEditing = YES;
    mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

    // overlay on top of camera lens view
    UIImageView *cameraOverlayView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Overlay2.png"]];
    cameraOverlayView.alpha = 0.0f;
    mediaPicker.cameraOverlayView = cameraOverlayView;

    // animate the fade in after the shutter opens
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:2.2f];
    cameraOverlayView.alpha = 1.0f;
    [UIView commitAnimations];

    [self presentViewController:mediaPicker animated:YES completion:Nil];

}

如何使用叠加图像保存捕获的图像?那就是我需要将捕获的图像和叠加保存为单个图像。

2 个答案:

答案 0 :(得分:0)

我做过类似的事情,你做的是拿一个UIView作为一个容器视图,现在添加两个I mage视图到它,比如我在代码中完成的 创建容器视图并添加两个ImageView,使其看起来像在storyBoard中的下面

现在只使用此代码

   UIGraphicsBeginImageContextWithOptions(containerView.bounds.size, view.opaque, 0.0);

    [containerView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;

你会得到这个img,是两个ImageViews的组合图像

答案 1 :(得分:0)

        imgPicker = [[UIImagePickerController alloc] init];
    imgPicker.allowsEditing = NO;
    imgPicker.delegate   = self;
    imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imgPicker.showsCameraControls=NO;
    imgPicker.extendedLayoutIncludesOpaqueBars = YES;
    imgPicker.edgesForExtendedLayout = YES;
    imgPicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
    imgPicker.cameraCaptureMode=UIImagePickerControllerQualityTypeHigh;

    imgPicker.cameraViewTransform = CGAffineTransformScale(imgPicker.cameraViewTransform, CAMERA_TRANSFORMWidth , CAMERA_TRANSFORM);


    UIView* overlayView = [[UIView alloc] initWithFrame:imgPicker.view.frame];
    CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 25.0);
    imgPicker.cameraViewTransform = CGAffineTransformScale(translate, CAMERA_TRANSFORM, CAMERA_TRANSFORM);
    imgPicker.cameraOverlayView = overlayView;



    UIImageView *stripImageVW=[[UIImageView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height-70,self.view.frame.size.width,70)];

    [stripImageVW setImage:[UIImage imageNamed:@"Black_StripView"]];
    [overlayView addSubview:stripImageVW];