我创建了一个叠加图像用作水印,但图像偏移了。我已经把下面的代码放在了Ivan Karpan这篇帖子的基础上:Watermark image on real time on camera view in iphone
- (void)btCamera_TouchUpInside:(UIButton *)button
{
// Create the image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraViewTransform = CGAffineTransformScale(imagePicker.cameraViewTransform, 1.24299, 1.24299);
imagePicker.allowsImageEditing = NO;
imagePicker.delegate = self;
UIImageView * ivWatermark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Watermark.png"]];
ivWatermark.alpha = WATERMARK_ALPHA;
ivWatermark.contentMode = UIViewContentModeTopLeft;
ivWatermark.frame = self.view.frame;
imagePicker.cameraOverlayView = ivWatermark;
[ivWatermark release];
// Show the image picker
[self presentModalViewController:imagePicker animated:YES];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
[(UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage] drawInRect:CGRectMake(0, 0, 320, 480)];
[[UIImage imageNamed:@"Watermark.png"] drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:WATERMARK_ALPHA];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
imageView.image = image;
UIGraphicsEndImageContext();
[picker dismissModalViewControllerAnimated:YES];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
我首先创建imagePicker,然后将水印添加到该摄像机图像,但图像是偏移的。我还根据此处发现的另一篇文章愚弄了缩放:Using the camera on the iPad/iPhone with an overlay
此外,我已阅读其他有关将叠加图像添加到相机图片的文章,但它们似乎都有同样的问题。
任何帮助都会很棒?
由于