ios - UIImagePickerController overlayview在预览中倒置

标签 ios camera uiimagepickercontroller overlay-view

我想在拍摄照片时添加叠加 View 。我可以成功添加叠加 View 并拍摄照片。

点击捕获按钮后,将显示预览。在该预览屏幕中,叠加 View 是上下颠倒的(大约 20 到 30 像素)。

选择 时使用 按钮,拍摄的图像保存在相册中。在其中,图像很好。它仅在预览期间颠倒。

我附上了下面的代码,请指导我的错误。

-(void)viewDidLoad {

// ...
// Some other actions...

OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

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.24299, 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
    UIImage *overlayImage  = [UIImage imageNamed:@"img3.png"]; //foverlayImage image

    CGSize newSize = image.size;
    UIGraphicsBeginImageContext( newSize );

    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

    // Apply supplied opacity if applicable
    [overlayImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:1.0];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(newImage, 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];
    // All is well
else 
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];

    [alert show];
    alert.delegate = self;
    [alert release];
}

在 OverlayView.m 中
- (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, 0, 320, 460);
        [self addSubview:overlayGraphicView];
        [overlayGraphicView release];

    }

    return self;
}

提前致谢。

最佳答案

嘿,我正在寻找同样的东西,并遇到了这个链接,这解释了为什么它似乎是颠倒的!希望能帮助到你
http://trandangkhoa.blogspot.co.uk/2009/07/iphone-os-drawing-image-and-stupid.html

关于ios - UIImagePickerController overlayview在预览中倒置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12250531/

相关文章:

android - 使用 ACTION_GET_CONTENT 在 Android on 2.1 上选取图片和视频

objective-c - ipad UIImagePickerController 视频质量

ios - 无法在 iOS 上的 Swift 中将 base64 字符串发送到服务器

ios - 寻找触手可及的通用蓝牙设备

ios - 以日期和时间两种不同的字符串格式转换格式为 "19-07-2018 08:10:24"的字符串

ios - 拉伸(stretch)图像的两侧但不是 uibutton 的中心

android - Camera2Video Api 全屏预览和视频质量

OpenCV 连续速度测量使用相机

ios - 打开UIImagePickerController自定义相册?

ios - 自定义 UIPicker