Tag: avcaptureoutput

AVCaptureStillImageOutput&UIImagePNGRepresentation

对于我认为不应该那么困难的事情,我很难过,所以我认为我必须从错误的angular度看问题。 为了解如何AVCaptureStillImageOutput和相机工作,我做了一个小应用程序。 这个应用程序能够拍照并将其保存为PNG文件(我不需要JPEG)。 下次启动应用程序时,会检查文件是否存在,如果存在,则将存储在文件内的图像用作应用程序的背景视图。 这个想法很简单。 问题是它不起作用。 如果有人能告诉我我做错了什么,这将是非常有帮助的。 我希望图片以与显示时相同的方式出现在背景上,但是它被旋转或者尺寸错误.. .. 这里是相关的代码(如果需要,我可以提供更多的信息)。 viewDidLoad方法: override func viewDidLoad() { super.viewDidLoad() // For the photo capture: captureSession.sessionPreset = AVCaptureSessionPresetHigh // Select the appropriate capture devices: for device in AVCaptureDevice.devices() { // Make sure this particular device supports video. if (device.hasMediaType(AVMediaTypeVideo)) { // Finally check the position and confirm we've got […]

AVCaptureStillImageOutput区域select

在用Swift编写的iOS应用程序中保存从相机拍摄的图像时,这是我面临的挑战。 我并不是完全按照自己的意愿去储蓄,而是在储蓄之外,而不是那么做。 这是这个问题的两个相关的代码块。 首先在会议开始的地方,人们可以看到我只看着一个椭圆形区域: previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) previewLayer?.frame = self.view.layer.frame self.view.layer.addSublayer(previewLayer!) let maskLayer = CAShapeLayer() maskLayer.path = CGPathCreateWithEllipseInRect(CGRect(x: 50.0, y: 100.0, width: 200.0, height: 100.0), nil) previewLayer!.mask = maskLayer captureSession.startRunning() 第二,保存图像并停止会话: if captureSession.running { if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) { stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) { (imageDataSampleBuffer, error) -> Void in if error == nil { let imageData […]

iOS:错误__connection_block_invoke_2:连接中断

控制台中的Xcode / iOS 8 / AVFoundation相关的错误: error in __connection_block_invoke_2: Connection interrupted 我只是将AVCaptureVideoDataOutput添加到苹果的示例应用程序“AVCamManualUsingtheManualCaptureAPI” 我补充说的是: // CoreImage wants BGRA pixel format NSDictionary *outputSettings = @{ (id)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInteger:kCVPixelFormatType_32BGRA]}; // create and configure video data output AVCaptureVideoDataOutput *videoDataOutput = [[AVCaptureVideoDataOutput alloc] init]; videoDataOutput.videoSettings = outputSettings; videoDataOutput.alwaysDiscardsLateVideoFrames = YES; [videoDataOutput setSampleBufferDelegate:self queue:sessionQueue]; 上面的代码插入到示例项目中: – (void)viewDidLoad { [super viewDidLoad]; […]