【问题标题】:iPhone: Camera Preview OverlayiPhone:相机预览覆盖
【发布时间】:2010-11-03 08:01:18
【问题描述】:

如何将叠加层 (UIImageView) 添加到相机预览和 处理涉及到这个?

我之前的尝试(例如,使用 UIImagePickerController 并将图像添加为子视图)失败了。

【问题讨论】:

  • 画得真棒!
  • 一张图说一千个字

标签: iphone uiimageview camera uiimagepickercontroller


【解决方案1】:

本教程讲解:http://www.musicalgeometry.com/?p=821

只需在叠加视图中添加一个 UIImage,而不是教程中显示的红色区域。

【讨论】:

  • +1,这显然是更好的答案。如果我没记错的话,cameraOverlayView 是在 3.1 SDK 中添加的。
  • 您好,我也需要该信息,但链接无效。还有其他教程吗?谢谢
  • @dtt101:您的链接不存在了! :未找到
  • 我在我的博客中添加了一个更新的教程,详细介绍了如何在 iOS 4 和更高版本中使用 AVCaptureSession 而不是 UIImagePicker 方法来执行此操作。 musicalgeometry.com/?p=1273
【解决方案2】:

对于你的实现文件:

- (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];
    }

创建一个 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;
    }

【讨论】:

    【解决方案3】:

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

    [window bringSubviewToFront:imageView];
    

    相机启动后。

    如果您想处理UIImageView 上的触摸,您只需将UIImageView 添加为具有透明背景的普通全屏View 的子视图,然后将 that 添加到窗口而是使用普通的UIViewController 子类,您可以使用它来处理触摸事件。

    【讨论】:

      【解决方案4】:

      查看相机叠加视图(在 3.1 及更高版本中可用)

      @property(nonatomic, retain) UIView *cameraOverlayView
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多