我正面臨一些真正的問題。我已經學習了幾個使用UIImagePickerController和AVFoundation在相機中添加疊加層的教程。一切工作都很好。我可以使用兩者在相機上添加疊加層。然而,我主要關心的是,當用戶點擊掃描按鈕時,提取該覆蓋視圖下的那部分圖像。我在覆蓋圖和按鈕中顯示白色視圖,因此只能檢索該白色視圖下的圖像。iOS相機覆蓋拍攝圖像
-(IBAction)cameraClicked:(id)sender {
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
if ([UIImagePickerController
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePickerController.cameraCaptureMode =
UIImagePickerControllerCameraCaptureModePhoto;
}
else {
self.imagePickerController.sourceType =
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
self.imagePickerController.showsCameraControls = NO;
self.imagePickerController.navigationBarHidden = YES;
self.imagePickerController.toolbarHidden = YES;
self.imagePickerController.wantsFullScreenLayout = YES;
self.imagePickerController.cameraViewTransform =
CGAffineTransformScale(self.imagePickerController.cameraViewTransform,
CAMERA_TRANSFORM_X,CAMERA_TRANSFORM_Y);
self.imagePickerController.cameraOverlayView = overlay;
[self presentViewController:self.imagePickerController animated:YES
completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CGRect cropRect;
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *crosshair = [UIImage imageNamed:@"overlay.png"];
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height));
[image drawInRect: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if(isIOS7)
cropRect = CGRectMake(10, 440, crosshair.size.width, crosshair.size.height);
else
cropRect = CGRectMake(10, 405, crosshair.size.width, crosshair.size.height);
CGImageRef imageRef = CGImageCreateWithImageInRect([smallImage CGImage], cropRect);
UIImage *setImage = [UIImage imageWithCGImage:imageRef];
self.finalImageView.image = setImage;
[self dismissViewControllerAnimated:YES completion:nil];
}
我已經更新了我的問題與代碼 – user2342321