3

我创建了一个覆盖图像用作水印,但图像被偏移。我在下面放了代码,该代码基于 Ivan Karpan 的这篇文章: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,然后将水印添加到该相机图像中,但图像是偏移的。根据此处找到的另一篇文章,我还对缩放进行了愚弄:在 iPad/iPhone 上使用带有叠加层的相机

此外,我还阅读了其他有关向相机图片添加叠加图像的文章,但它们似乎都存在相同的问题。

任何帮助都会很棒?

谢谢

4

0 回答 0