0
A
回答
0
如果您的意思是要显示实时视频流形式的相机,你可以使用GPUImage。
如果您只需拍摄静止图像,请使用AVFoundation的AVCaptureStillImageOutput。请参阅AVCam - Apple's sample code,您可以从中删除预览实况视频(AVCaptureVideoPreviewLayer
)的部分内容,并在需要时捕获静止图像。
//you'll need to create an AVCaptureSession
_session = [[AVCaptureSession alloc] init];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//there are steps here where you adjust capture device if needed
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if ([device supportsAVCaptureSessionPreset: AVCaptureSessionPreset640x480]) {
_session.sessionPreset = AVCaptureSessionPreset640x480;
}
_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];
[outputSettings release];
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in _stillImageOutput.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
[_session addOutput: _stillImageOutput];
[_session startRunning];
这段代码是用来拍照:
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in _stillImageOutput.connections)
{
for (AVCaptureInputPort *port in [connection inputPorts])
{
if ([[port mediaType] isEqual:AVMediaTypeVideo])
{
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
[_stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if (imageSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [UIImage imageWithData: imageData];
//do something with image or data
}
}
希望它能帮助。
相关问题
- 1. Android:如何延迟拍摄相机拍摄的特定帧?
- 2. 从相机拍摄信息
- 3. 从相机拍摄照片
- 4. 在mathematica拍摄相机在Raspberrypi
- 5. 如何在Android中拍摄自定义相机的截图?
- 6. 如何显示在Android中使用相机拍摄的图像
- 7. 如何在Android中使用相机拍摄多张图像
- 8. 用相机拍摄的图像叠加在android中拍摄的图像
- 9. 如何在摄像机拍摄中工作
- 10. 如何处理用相机拍摄的图像中的噪点
- 11. 如何在EMGUCV 3.1上拍摄我的相机屏幕截图?
- 12. 使用UIViewController(MonoTouch)相机拍摄照片
- 13. 相机意图拍摄两张图片
- 14. android用相机拍摄多个图像
- 15. android拍摄部分相机视图
- 16. iOS相机覆盖拍摄图像
- 17. 获取相机拍摄的图片
- 18. Android - 查找相机拍摄的方向
- 19. UIImageView从相机拍摄后旋转
- 20. android - 从相机拍摄图像
- 21. 无法拍摄图片相机
- 22. GPUImage相机拍摄五秒钟
- 23. 相机照片拍摄失败
- 24. IntentFilter相机和拍摄的照片
- 25. 的Android相机拍摄多张照片
- 26. 拍摄来自相机的照片
- 27. Android相机拍摄fileUri.getPath有时空
- 28. Monodroid使用相机拍摄照片
- 29. 如何在相册中查看相机应用拍摄照片异步
- 30. 在iOS中使用数码相机拍摄相机中的照片
在您的代码上发生此错误:由于未捕获异常'NSInvalidArgumentException'导致应用程序失败,原因:'*** - [AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection:completionHandler:] - 无效/无效连接已通过。 – user1188620
我不想发布完整的代码,因为它很庞大,可能会令人困惑。看看苹果的示例代码,并从那里除去所有你不需要的东西。 –
是的,它是工作谢谢! – user1188620