iPhone:相机预览叠加

Ste*_*fan 43 iphone camera uiimageview uiimagepickercontroller

如何UIImageView在相机预览中添加叠加()并处理此操作?

我之前尝试这样做(例如使用UIImagePickerController并将图像添加为子视图)失败了.

dtt*_*101 37

This tutorial explains it: http://www.musicalgeometry.com/?p=821

Just add a UIImage in the overlay view instead of the red area shown in the tutorial.

  • 我在我的博客中添加了一个更新的教程,详细说明了如何使用AVCaptureSession而不是UIImagePicker方法在iOS 4及更高版本中执行此操作.http://www.musicalgeometry.com/?p=1273 (3认同)
  • +1,这现在显然是更好的答案.如果我没弄错的话,在3.1 SDK中添加了cameraOverlayView. (2认同)

小智 10

对于您的实现文件:

- (IBAction)TakePicture:(id)sender {

    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

        // Delegate is self
        imagePicker.delegate = self;

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

        // Insert the overlay:
        imagePicker.cameraOverlayView = overlay;

       // Allow editing of image ?
        imagePicker.allowsImageEditing = YES;
        [imagePicker setCameraDevice:
        UIImagePickerControllerCameraDeviceFront];
        [imagePicker setAllowsEditing:YES];
        imagePicker.showsCameraControls=YES;
        imagePicker.navigationBarHidden=YES;
        imagePicker.toolbarHidden=YES;
        imagePicker.wantsFullScreenLayout=YES;

        self.library = [[ALAssetsLibrary alloc] init];

        // Show image picker
        [self presentModalViewController:imagePicker animated:YES];
    }
Run Code Online (Sandbox Code Playgroud)

创建一个UIView类并添加此代码

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code


            // 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:@"overlaygraphic.png"];
            UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
            overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
            [self addSubview:overlayGraphicView];

        }
        return self;
    }
Run Code Online (Sandbox Code Playgroud)


Ed *_*rty 3

您也许可以UIImageView直接添加 作为主窗口的子视图而不是UIImagePicker,它可能会工作得更好。只需确保以正确的顺序添加它们,或致电

[window bringSubviewToFront:imageView];
Run Code Online (Sandbox Code Playgroud)

相机升起后。

如果您想处理触摸,UIImageView您只需将其添加为具有透明背景的UIImageView普通全屏的子视图,然后将添加到窗口中,并使用可用于处理触摸事件的普通子类。ViewUIViewController