我在相机上添加了叠加层,并从相机拍摄了相同形状的物体。然后对点击的图像应用蒙版,以便我将获得具有该形状的图像,而其他区域将是白色的。但是掩盖后捕获的图像和图像并不相同。以下是最终图片
的屏幕截图我希望这个捕获的图像具有星形图像叠加内的区域
// create view for overlay
CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height-50);
UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect];
// prepare the image to overlay
UIImageView *overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star"]];
overlayImage.center = overlayView.center;
overlayImage.alpha = 0.6;
[overlayView.layer setOpaque:NO];
overlayView.opaque = NO;
[overlayView addSubview:overlayImage];
imagePicker.cameraOverlayView = overlayView;
[self presentViewController:imagePicker animated:YES completion:nil];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo {
[picker dismissViewControllerAnimated:YES completion:NULL];
UIImage *mask=[UIImage imageNamed:@"star"];
UIImage *newimage=[self maskImage:[editingInfo valueForKey:UIImagePickerControllerOriginalImage] withMask:mask];
[self.imageView setImage:newimage];
UIImageWriteToSavedPhotosAlbum(newimage, nil, nil, nil);
}