屏蔽后的叠加和图像未正确定位iOS

时间:2017-11-10 06:59:00

标签: ios image camera overlay masking

我在相机上添加了叠加层,并从相机拍摄了相同形状的物体。然后对点击的图像应用蒙版,以便我将获得具有该形状的图像,而其他区域将是白色的。但是掩盖后捕获的图​​像和图像并不相同。以下是最终图片enter image description here

的屏幕截图

我希望这个捕获的图像具有星形图像叠加内的区域

重叠

// 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);

}

0 个答案:

没有答案