写真をキャプチャするときにオーバーレイを追加しようとしました。プレビューでオーバーレイを正常に追加できましたが、写真キャプチャ ボタンをタップすると、オーバーレイ ビュー (約 40px) が上下逆になり、写真アルバムに画像を保存しようとしましたが、保存された画像にはオーバーレイ画像が含まれていません。
以下に添付しました。間違っている場合はご案内ください。
//In ViewDidLoad//
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
[picker setDelegate:self];
picker.showsCameraControls = YES;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, 1, 1.24299);
picker.cameraOverlayView = overlay;
[self presentModalViewController:picker animated:YES];
[picker release];
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
alert.delegate = self;
[alert release];
}
//In OverlayView.m file
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Clear the background of the overlay:
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// Load the image to show in the overlay:
UIImage *overlayGraphic = [UIImage imageNamed:@"img3.png"];
UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
overlayGraphicView.frame = CGRectMake(0, 50, 320, 430);
[self addSubview:overlayGraphicView];
[overlayGraphicView release];
}
return self;
}
よろしくお願いします