如何访问相机 &相机胶卷 Objective-C [英] How To Access Camera & Camera Roll Objective-C

查看:18
本文介绍了如何访问相机 &相机胶卷 Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个需要访问相机和相机胶卷的通用 iOS 应用程序.我会怎么做呢?我还没有要展示的代码,因为该应用主要基于此.

I am making a Universal iOS Application which needs to access the camera and the camera roll. How would i go about this? I have no code to show yet because the app is mainly based around this.

推荐答案

此答案仅适用于物理设备!

This answer relevant on physical device ONLY!

访问摄像头:

- (void)takePhoto {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:NULL];

}

访问相机胶卷:

- (void)selectPhoto {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:picker animated:YES completion:NULL];


}

实现 UIImagePickerController 的委托方法:

Implementing the Delegate Methods of UIImagePickerController:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;

    [picker dismissViewControllerAnimated:YES completion:NULL];

}

还有这个:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissViewControllerAnimated:YES completion:NULL];

}

源代码这里

这篇关于如何访问相机 &相机胶卷 Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆