【问题标题】:Take picture and set it to UIImageView in iOS [duplicate]拍照并将其设置为iOS中的UIImageView [重复]
【发布时间】:2013-03-14 14:39:05
【问题描述】:

有没有办法在不通过 Apple 控件的情况下在 iPad 上拍照?我见过很多这样的应用程序,

例如,当您在 iPhone 中添加新联系人时,在左上角显示add photo,当我们点击它时,相机会打开并拍照并保存到add photo..

我想实现相同的功能.. 可以在 iPad 上实现吗?

【问题讨论】:

    标签: iphone ios ipad uiimageview camera


    【解决方案1】:

    您需要做的是,首先添加一个按钮,标题为“添加照片”或自定义图像。

    然后点击按钮添加以下代码:

        if (([UIImagePickerController isSourceTypeAvailable:
                  UIImagePickerControllerSourceTypeCamera] == NO)
                return NO;
    
            UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
            cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController: cameraUI animated: YES completion:nil];
    

    它将打开相机,然后单击图像,然后点击“使用”,您必须实现 UIImagePickerControllerDelegate 方法 imagePickerController:didFinishPickingMediaWithInfo: 然后将 UIImage 存储到您想要的任何位置,使用任何你想要的文件名,使用 NSFileManager 方法。

    【讨论】:

    • 很好,它正在工作,但是,相机拍摄图像位之后它不会加载我已经进入imageview的图像这是我的代码- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; [imgVw setImage:image]; imgVw.contentMode = UIViewContentModeScaleAspectFill; }
    • 我认为可能还有其他问题,因为这段代码在我的最后工作完全正常,并且它也在 imageView 中显示图像
    【解决方案2】:

    使用图像选择器控制器,您可以使用您在问题中描述的相同功能。

    为此,您需要将图片转换为图像数据并在uiimageview中显示

    你可以参考这个:UIImageView Class Reference

    这也将为您提供示例。

    Taking a picture from the camera and show it in a UIImageView的这个答案将为您提供正确的答案..

    享受编程!

    【讨论】:

      猜你喜欢
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      相关资源
      最近更新 更多