首先我会说我是 objective-c 和 iOS 编程的新手。
我想做的是将相机显示为 View 的一部分,如屏幕上部的矩形,我应该从哪里开始?
(“相机 View ”的 GUI 组件是什么?AVCamCaptureManager
或 UIImagePickerController
?)
最佳答案
您可以使用 AVFoundation 来做到这一点。一个好的起点是观看与 AVFoundation 和 Camera 相关的 WWDC 视频(自 2011 年起)。
苹果的example code for AVCam project是一个很好的起点。
这是您可以执行的操作的示例。
首先您需要实例化一个捕获 session :
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPreset1280x720;
然后您必须创建输入并将其添加到 session 中,以便从您的设备相机获取图像:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
NSLog(@"Couldn't create video capture device");
}
[session addInput:input];
然后您使用 AVCaptureVideoPreviewLayer 在层中呈现来自您的设备相机的图像:
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
最后,您只需设置该特定层的框架(您需要的 UI 部分)并将其添加到所需的 View 并开始 session 捕获。
关于iphone - 相机 View 作为 iOS 中的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19024832/