UIImagePickerController正确地覆盖了它上面的图像

时间:2014-03-10 14:42:35

标签: ios iphone objective-c uiimageview uiimagepickercontroller

关于这个问题:

  • 设备:iPod touch第4代(640 * 960视网膜显示分辨率)
  • 操作系统:iOS 6
  • 开发工具包: XCode 5.0.2
  • 源代码我尝试修改: PhotoPicker example
  • 目标:在UIImagePickerController视图顶部添加图片

说明

我正在修改Apple的PhotoPicker example,目的是在拍照前添加显示在相机镜头上方的自定义PNG图像。图像将指示用户必须放置他/她的脸部。

下图显示了我得到的和我想要的东西。正如您所看到的那样,原始图像似乎重新缩放,变得太大

enter image description here

点击“相机”按钮时调用的主要方法如下。我修改了它将 UIImageView 子视图添加到 imagePickerController ,在那里我用包含原始640 * 960图像的UIImage初始化了UIImageView。

当我在我的iPod第4代(640 * 960)上运行这段代码时,似乎缩放的图像很多。如何修复下面的代码以使图像完美覆盖相机?(点应出现在中心,黑色边框出现在边框中)

 - (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
    if (self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
    }

    if (self.capturedImages.count > 0)
    {
        [self.capturedImages removeAllObjects];
    }

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    imagePickerController.sourceType = sourceType;
    imagePickerController.delegate = self;

    if (sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        /*
         The user wants to use the camera interface. Set up our custom overlay view for the camera.
         */
        imagePickerController.showsCameraControls = NO;


        // Set rear camera
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;

        /*
         Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil.
         */
        [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
        self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
        imagePickerController.cameraOverlayView = self.overlayView;
        self.overlayView = nil;

        UIImage * imageOfFaces = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo border" ofType:@"png"]];

        UIImageView * imageViewOfFaces = [[UIImageView alloc] initWithImage:imageOfFaces];

        [imagePickerController.view addSubview:imageViewOfFaces];
       [imageViewOfFaces sizeToFit];
    }

    self.imagePickerController = imagePickerController;
    [self presentViewController:self.imagePickerController animated:YES completion:nil];
}

全尺寸图片

这是我要叠加的PNG图像(640w * 960h像素):

enter image description here

然而这是结果:

enter image description here

1 个答案:

答案 0 :(得分:2)

确保您的图片具有如下的视网膜后缀:

image@2x.png
相关问题