[英]save image with overlay in the camera view
I have added a overlay over the camera view using the below code,我使用以下代码在相机视图上添加了一个叠加层,
- (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];
}
How to save the captured image with overlay image in it?如何保存带有叠加图像的捕获图像? That is I need to save both the captured image and overlay as a single image.也就是说,我需要将捕获的图像和覆盖图保存为单个图像。
I had done something like this , What you do is take a UIView
which would act as a container view and now add two I mage view to It such as I have done in code below.我做过这样的事情,你所做的是采用一个UIView
作为容器视图,现在向它添加两个 I mage 视图,就像我在下面的代码中所做的那样。 Create Container View and add two ImageView so that It looks Like below in your storyBoard创建容器视图并添加两个 ImageView,使其在您的故事板中如下所示
now just use this code现在只需使用此代码
UIGraphicsBeginImageContextWithOptions(
containerView.bounds.size,
view.opaque,
0.0
);
[containerView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
This img which you would get, is the combined Image of the two ImageViews您将获得的这个 img 是两个 ImageView 的组合图像
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.