Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我已经看到了这个问题的其他几乎答案,但似乎无法让它工作.我正在从AVMediaTypeVideo捕捉一个图像,它的方向总是UI ImageOrientation 3(我不知道这在现实中意味着什么). 我试图使用状态栏方向纠正它,但似乎没有任何影响.我不需要将这些图像保存到相机胶卷,它现在就在那里验证.我不确定这对方向是否有任何影响. import UIKitimport AVFoundation 我已经看到了这个问题的其他几乎答案,但似乎无法让它工作.我正在从AVMediaTypeVIDeo捕捉一个图像,它的方向总是UI ImageOrIEntation 3(我不知道这在现实中意味着什么).

我试图使用状态栏方向纠正它,但似乎没有任何影响.我不需要将这些图像保存到相机胶卷,它现在就在那里验证.我不确定这对方向是否有任何影响.

import UIKitimport AVFoundationclass VIEwController: UIVIEwController {let captureSession = AVCaptureSession()let stillimageOutput = AVCaptureStillimageOutput()var avCaptureVIDeoPrevIEw : AVCaptureVIDeoPrevIEwLayer?var error: NSError?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    let devices = AVCaptureDevice.devices().filter{ 
import UIKitimport AVFoundationclass VIEwController: UIVIEwController {let captureSession = AVCaptureSession()let stillimageOutput = AVCaptureStillimageOutput()var avCaptureVIDeoPrevIEw : AVCaptureVIDeoPrevIEwLayer?var error: NSError?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    let devices = AVCaptureDevice.devices().filter{ [+++].hasMediaType(AVMediaTypeVIDeo) }    if let captureDevice = devices.first as? AVCaptureDevice  {        captureSession.addinput(AVCaptureDeviceinput(device: captureDevice,action:"savetoCamera:"))            vIEw.addSubvIEw(cameraPrevIEw)        }    }    // Add a selfIE button if device is capable    for device in devices {        if device.position == AVCaptureDeviceposition.Front {            // Add selfIE button            println("selfIE capable")        }    }}overrIDe func vIEwWillLayoutSubvIEws() {    if avCaptureVIDeoPrevIEw != nil {        // OrIEntation        if (avCaptureVIDeoPrevIEw!.connection.supportsVIDeoOrIEntation == true) {            var newOrIEntation : AVCaptureVIDeoOrIEntation?            switch UIDevice.currentDevice().orIEntation {            case UIDeviceOrIEntation.Portrait:                newOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            case UIDeviceOrIEntation.PortraitUpsIDeDown:                newOrIEntation = AVCaptureVIDeoOrIEntation.PortraitUpsIDeDown            case UIDeviceOrIEntation.Landscapeleft:                newOrIEntation = AVCaptureVIDeoOrIEntation.LandscapeRight;            case UIDeviceOrIEntation.LandscapeRight:                newOrIEntation = AVCaptureVIDeoOrIEntation.Landscapeleft            default:                newOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            }            avCaptureVIDeoPrevIEw!.connection.vIDeoOrIEntation = newOrIEntation!        }        // Frame         avCaptureVIDeoPrevIEw!.bounds = CGRectMake(0.0,vIEw.bounds.mIDY)        avCaptureVIDeoPrevIEw!.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill    }}func savetoCamera(sender: UITapGestureRecognizer) {    if let vIDeoConnection = stillimageOutput.connectionWithMediaType(AVMediaTypeVIDeo) {        stillimageOutput.captureStillimageAsynchronouslyFromConnection(vIDeoConnection) {            (imageDataSampleBuffer,error) -> VoID in            var image = UIImage(data: AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(imageDataSampleBuffer))            var imageOrIEntation : UIImageOrIEntation?            switch UIDevice.currentDevice().orIEntation {            case UIDeviceOrIEntation.PortraitUpsIDeDown:                imageOrIEntation = UIImageOrIEntation.left            case UIDeviceOrIEntation.LandscapeRight:                imageOrIEntation = UIImageOrIEntation.Down            case UIDeviceOrIEntation.Landscapeleft:                imageOrIEntation = UIImageOrIEntation.Up            case UIDeviceOrIEntation.Portrait:                imageOrIEntation = UIImageOrIEntation.Right            default:                imageOrIEntation = UIImageOrIEntation.Right            }            var newImage = UIImage(CGImage: image!.CGImage,orIEntation: imageOrIEntation!)            UIImageWritetoSavedPhotosAlbum(newImage!,nil)        }    }}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()}}
.hasMediaType(AVMediaTypeVIDeo) } if let captureDevice = devices.first as? AVCaptureDevice { captureSession.addinput(AVCaptureDeviceinput(device: captureDevice,error: &error)) captureSession.sessionPreset = AVCaptureSessionPresetMedium captureSession.startRunning() stillimageOutput.outputSettings = [AVVIDeoCodecKey:AVVIDeoCodecJPEG] if captureSession.canAddOutput(stillimageOutput) { captureSession.addOutput(stillimageOutput) } avCaptureVIDeoPrevIEw = AVCaptureVIDeoPrevIEwLayer(session: captureSession) if let prevIEwLayer = avCaptureVIDeoPrevIEw { prevIEwLayer.bounds = CGRectMake(0.0,0.0,vIEw.bounds.size.wIDth,vIEw.bounds.size.height) prevIEwLayer.position = CGPointMake(vIEw.bounds.mIDX,vIEw.bounds.mIDY) prevIEwLayer.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill let cameraPrevIEw = UIVIEw(frame: CGRectMake(0.0,vIEw.bounds.size.height)) cameraPrevIEw.layer.addSublayer(prevIEwLayer) cameraPrevIEw.addGestureRecognizer(UITapGestureRecognizer(target: self,action:"savetoCamera:")) vIEw.addSubvIEw(cameraPrevIEw) } } // Add a selfIE button if device is capable for device in devices { if device.position == AVCaptureDeviceposition.Front { // Add selfIE button println("selfIE capable") } }}overrIDe func vIEwWillLayoutSubvIEws() { if avCaptureVIDeoPrevIEw != nil { // OrIEntation if (avCaptureVIDeoPrevIEw!.connection.supportsVIDeoOrIEntation == true) { avCaptureVIDeoPrevIEw!.connection.vIDeoOrIEntation = interfaceOrIEntationToVIDeoOrIEntation(UIApplication.sharedApplication().statusbarOrIEntation) } // Frame avCaptureVIDeoPrevIEw!.bounds = CGRectMake(0.0,vIEw.bounds.size.height) avCaptureVIDeoPrevIEw!.position = CGPointMake(vIEw.bounds.mIDX,vIEw.bounds.mIDY) avCaptureVIDeoPrevIEw!.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill }}func interfaceOrIEntationToVIDeoOrIEntation(orIEntation: UIInterfaceOrIEntation) -> AVCaptureVIDeoOrIEntation { switch orIEntation { case UIInterfaceOrIEntation.Portrait: return AVCaptureVIDeoOrIEntation.Portrait case UIInterfaceOrIEntation.PortraitUpsIDeDown: return AVCaptureVIDeoOrIEntation.PortraitUpsIDeDown case UIInterfaceOrIEntation.Landscapeleft: return AVCaptureVIDeoOrIEntation.Landscapeleft case UIInterfaceOrIEntation.LandscapeRight: return AVCaptureVIDeoOrIEntation.LandscapeRight default: return AVCaptureVIDeoOrIEntation.Portrait }}func savetoCamera(sender: UITapGestureRecognizer) { if let vIDeoConnection = stillimageOutput.connectionWithMediaType(AVMediaTypeVIDeo) { stillimageOutput.captureStillimageAsynchronouslyFromConnection(vIDeoConnection) { (imageDataSampleBuffer,error) -> VoID in var image = UIImage(data: AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(imageDataSampleBuffer)) // this is not working var orIEntation : UIImageOrIEntation? switch UIApplication.sharedApplication().statusbarOrIEntation.rawValue { case 1: orIEntation = UIImageOrIEntation.Up case 3: orIEntation = UIImageOrIEntation.left case 4: orIEntation = UIImageOrIEntation.Right default: orIEntation = UIImageOrIEntation.Up } let newImage = UIImage(CGImage: image?.CGImage,scale: 1.0,orIEntation: orIEntation!) UIImageWritetoSavedPhotosAlbum(newImage,nil,nil) } }}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}}
解决方法 编辑,这不适用于使用前置摄像头拍摄的照片,它们在原生照片应用程序中显示正常,但在Mac上的照片中共享或从parse.com加载时不能显示.

感谢@XJones在这里回答Why does AVCaptureVideoOrientation landscape modes result in upside down still images?

[+++] 总结

以上是内存溢出为你收集整理的ios – AVMediaTypeVideo捕获静止图像方向全部内容,希望文章能够帮你解决ios – AVMediaTypeVideo捕获静止图像方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我已经看到了这个问题的其他几乎答案,但似乎无法让它工作.我正在从AVMediaTypeVideo捕捉一个图像,它的方向总是UI ImageOrientation 3(我不知道这在现实中意味着什么). 我试图使用状态栏方向纠正它,但似乎没有任何影响.我不需要将这些图像保存到相机胶卷,它现在就在那里验证.我不确定这对方向是否有任何影响. import UIKitimport AVFoundation 我已经看到了这个问题的其他几乎答案,但似乎无法让它工作.我正在从AVMediaTypeVIDeo捕捉一个图像,它的方向总是UI ImageOrIEntation 3(我不知道这在现实中意味着什么).

我试图使用状态栏方向纠正它,但似乎没有任何影响.我不需要将这些图像保存到相机胶卷,它现在就在那里验证.我不确定这对方向是否有任何影响.

import UIKitimport AVFoundationclass VIEwController: UIVIEwController {let captureSession = AVCaptureSession()let stillimageOutput = AVCaptureStillimageOutput()var avCaptureVIDeoPrevIEw : AVCaptureVIDeoPrevIEwLayer?var error: NSError?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    let devices = AVCaptureDevice.devices().filter{ 
import UIKitimport AVFoundationclass VIEwController: UIVIEwController {let captureSession = AVCaptureSession()let stillimageOutput = AVCaptureStillimageOutput()var avCaptureVIDeoPrevIEw : AVCaptureVIDeoPrevIEwLayer?var error: NSError?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    let devices = AVCaptureDevice.devices().filter{ .hasMediaType(AVMediaTypeVIDeo) }    if let captureDevice = devices.first as? AVCaptureDevice  {        captureSession.addinput(AVCaptureDeviceinput(device: captureDevice,action:"savetoCamera:"))            vIEw.addSubvIEw(cameraPrevIEw)        }    }    // Add a selfIE button if device is capable    for device in devices {        if device.position == AVCaptureDeviceposition.Front {            // Add selfIE button            println("selfIE capable")        }    }}overrIDe func vIEwWillLayoutSubvIEws() {    if avCaptureVIDeoPrevIEw != nil {        // OrIEntation        if (avCaptureVIDeoPrevIEw!.connection.supportsVIDeoOrIEntation == true) {            var newOrIEntation : AVCaptureVIDeoOrIEntation?            switch UIDevice.currentDevice().orIEntation {            case UIDeviceOrIEntation.Portrait:                newOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            case UIDeviceOrIEntation.PortraitUpsIDeDown:                newOrIEntation = AVCaptureVIDeoOrIEntation.PortraitUpsIDeDown            case UIDeviceOrIEntation.Landscapeleft:                newOrIEntation = AVCaptureVIDeoOrIEntation.LandscapeRight;            case UIDeviceOrIEntation.LandscapeRight:                newOrIEntation = AVCaptureVIDeoOrIEntation.Landscapeleft            default:                newOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            }            avCaptureVIDeoPrevIEw!.connection.vIDeoOrIEntation = newOrIEntation!        }        // Frame         avCaptureVIDeoPrevIEw!.bounds = CGRectMake(0.0,vIEw.bounds.mIDY)        avCaptureVIDeoPrevIEw!.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill    }}func savetoCamera(sender: UITapGestureRecognizer) {    if let vIDeoConnection = stillimageOutput.connectionWithMediaType(AVMediaTypeVIDeo) {        stillimageOutput.captureStillimageAsynchronouslyFromConnection(vIDeoConnection) {            (imageDataSampleBuffer,error) -> VoID in            var image = UIImage(data: AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(imageDataSampleBuffer))            var imageOrIEntation : UIImageOrIEntation?            switch UIDevice.currentDevice().orIEntation {            case UIDeviceOrIEntation.PortraitUpsIDeDown:                imageOrIEntation = UIImageOrIEntation.left            case UIDeviceOrIEntation.LandscapeRight:                imageOrIEntation = UIImageOrIEntation.Down            case UIDeviceOrIEntation.Landscapeleft:                imageOrIEntation = UIImageOrIEntation.Up            case UIDeviceOrIEntation.Portrait:                imageOrIEntation = UIImageOrIEntation.Right            default:                imageOrIEntation = UIImageOrIEntation.Right            }            var newImage = UIImage(CGImage: image!.CGImage,orIEntation: imageOrIEntation!)            UIImageWritetoSavedPhotosAlbum(newImage!,nil)        }    }}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()}}
.hasMediaType(AVMediaTypeVIDeo) } if let captureDevice = devices.first as? AVCaptureDevice { captureSession.addinput(AVCaptureDeviceinput(device: captureDevice,error: &error)) captureSession.sessionPreset = AVCaptureSessionPresetMedium captureSession.startRunning() stillimageOutput.outputSettings = [AVVIDeoCodecKey:AVVIDeoCodecJPEG] if captureSession.canAddOutput(stillimageOutput) { captureSession.addOutput(stillimageOutput) } avCaptureVIDeoPrevIEw = AVCaptureVIDeoPrevIEwLayer(session: captureSession) if let prevIEwLayer = avCaptureVIDeoPrevIEw { prevIEwLayer.bounds = CGRectMake(0.0,0.0,vIEw.bounds.size.wIDth,vIEw.bounds.size.height) prevIEwLayer.position = CGPointMake(vIEw.bounds.mIDX,vIEw.bounds.mIDY) prevIEwLayer.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill let cameraPrevIEw = UIVIEw(frame: CGRectMake(0.0,vIEw.bounds.size.height)) cameraPrevIEw.layer.addSublayer(prevIEwLayer) cameraPrevIEw.addGestureRecognizer(UITapGestureRecognizer(target: self,action:"savetoCamera:")) vIEw.addSubvIEw(cameraPrevIEw) } } // Add a selfIE button if device is capable for device in devices { if device.position == AVCaptureDeviceposition.Front { // Add selfIE button println("selfIE capable") } }}overrIDe func vIEwWillLayoutSubvIEws() { if avCaptureVIDeoPrevIEw != nil { // OrIEntation if (avCaptureVIDeoPrevIEw!.connection.supportsVIDeoOrIEntation == true) { avCaptureVIDeoPrevIEw!.connection.vIDeoOrIEntation = interfaceOrIEntationToVIDeoOrIEntation(UIApplication.sharedApplication().statusbarOrIEntation) } // Frame avCaptureVIDeoPrevIEw!.bounds = CGRectMake(0.0,vIEw.bounds.size.height) avCaptureVIDeoPrevIEw!.position = CGPointMake(vIEw.bounds.mIDX,vIEw.bounds.mIDY) avCaptureVIDeoPrevIEw!.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill }}func interfaceOrIEntationToVIDeoOrIEntation(orIEntation: UIInterfaceOrIEntation) -> AVCaptureVIDeoOrIEntation { switch orIEntation { case UIInterfaceOrIEntation.Portrait: return AVCaptureVIDeoOrIEntation.Portrait case UIInterfaceOrIEntation.PortraitUpsIDeDown: return AVCaptureVIDeoOrIEntation.PortraitUpsIDeDown case UIInterfaceOrIEntation.Landscapeleft: return AVCaptureVIDeoOrIEntation.Landscapeleft case UIInterfaceOrIEntation.LandscapeRight: return AVCaptureVIDeoOrIEntation.LandscapeRight default: return AVCaptureVIDeoOrIEntation.Portrait }}func savetoCamera(sender: UITapGestureRecognizer) { if let vIDeoConnection = stillimageOutput.connectionWithMediaType(AVMediaTypeVIDeo) { stillimageOutput.captureStillimageAsynchronouslyFromConnection(vIDeoConnection) { (imageDataSampleBuffer,error) -> VoID in var image = UIImage(data: AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(imageDataSampleBuffer)) // this is not working var orIEntation : UIImageOrIEntation? switch UIApplication.sharedApplication().statusbarOrIEntation.rawValue { case 1: orIEntation = UIImageOrIEntation.Up case 3: orIEntation = UIImageOrIEntation.left case 4: orIEntation = UIImageOrIEntation.Right default: orIEntation = UIImageOrIEntation.Up } let newImage = UIImage(CGImage: image?.CGImage,scale: 1.0,orIEntation: orIEntation!) UIImageWritetoSavedPhotosAlbum(newImage,nil,nil) } }}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}}
解决方法 编辑,这不适用于使用前置摄像头拍摄的照片,它们在原生照片应用程序中显示正常,但在Mac上的照片中共享或从parse.com加载时不能显示.

感谢@XJones在这里回答Why does AVCaptureVideoOrientation landscape modes result in upside down still images?

[+++] 总结

以上是内存溢出为你收集整理的ios – AVMediaTypeVideo捕获静止图像方向全部内容,希望文章能够帮你解决ios – AVMediaTypeVideo捕获静止图像方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – AVMediaTypeVideo捕获静止图像方向_app_内存溢出

ios – AVMediaTypeVideo捕获静止图像方向

ios – AVMediaTypeVideo捕获静止图像方向,第1张

概述我已经看到了这个问题的其他几乎答案,但似乎无法让它工作.我正在从AVMediaTypeVideo捕捉一个图像,它的方向总是UI ImageOrientation 3(我不知道这在现实中意味着什么). 我试图使用状态栏方向纠正它,但似乎没有任何影响.我不需要将这些图像保存到相机胶卷,它现在就在那里验证.我不确定这对方向是否有任何影响. import UIKitimport AVFoundation 我已经看到了这个问题的其他几乎答案,但似乎无法让它工作.我正在从AVMediaTypeVIDeo捕捉一个图像,它的方向总是UI ImageOrIEntation 3(我不知道这在现实中意味着什么).

我试图使用状态栏方向纠正它,但似乎没有任何影响.我不需要将这些图像保存到相机胶卷,它现在就在那里验证.我不确定这对方向是否有任何影响.

import UIKitimport AVFoundationclass VIEwController: UIVIEwController {let captureSession = AVCaptureSession()let stillimageOutput = AVCaptureStillimageOutput()var avCaptureVIDeoPrevIEw : AVCaptureVIDeoPrevIEwLayer?var error: NSError?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    let devices = AVCaptureDevice.devices().filter{ 
import UIKitimport AVFoundationclass VIEwController: UIVIEwController {let captureSession = AVCaptureSession()let stillimageOutput = AVCaptureStillimageOutput()var avCaptureVIDeoPrevIEw : AVCaptureVIDeoPrevIEwLayer?var error: NSError?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    let devices = AVCaptureDevice.devices().filter{ .hasMediaType(AVMediaTypeVIDeo) }    if let captureDevice = devices.first as? AVCaptureDevice  {        captureSession.addinput(AVCaptureDeviceinput(device: captureDevice,action:"savetoCamera:"))            vIEw.addSubvIEw(cameraPrevIEw)        }    }    // Add a selfIE button if device is capable    for device in devices {        if device.position == AVCaptureDeviceposition.Front {            // Add selfIE button            println("selfIE capable")        }    }}overrIDe func vIEwWillLayoutSubvIEws() {    if avCaptureVIDeoPrevIEw != nil {        // OrIEntation        if (avCaptureVIDeoPrevIEw!.connection.supportsVIDeoOrIEntation == true) {            var newOrIEntation : AVCaptureVIDeoOrIEntation?            switch UIDevice.currentDevice().orIEntation {            case UIDeviceOrIEntation.Portrait:                newOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            case UIDeviceOrIEntation.PortraitUpsIDeDown:                newOrIEntation = AVCaptureVIDeoOrIEntation.PortraitUpsIDeDown            case UIDeviceOrIEntation.Landscapeleft:                newOrIEntation = AVCaptureVIDeoOrIEntation.LandscapeRight;            case UIDeviceOrIEntation.LandscapeRight:                newOrIEntation = AVCaptureVIDeoOrIEntation.Landscapeleft            default:                newOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            }            avCaptureVIDeoPrevIEw!.connection.vIDeoOrIEntation = newOrIEntation!        }        // Frame         avCaptureVIDeoPrevIEw!.bounds = CGRectMake(0.0,vIEw.bounds.mIDY)        avCaptureVIDeoPrevIEw!.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill    }}func savetoCamera(sender: UITapGestureRecognizer) {    if let vIDeoConnection = stillimageOutput.connectionWithMediaType(AVMediaTypeVIDeo) {        stillimageOutput.captureStillimageAsynchronouslyFromConnection(vIDeoConnection) {            (imageDataSampleBuffer,error) -> VoID in            var image = UIImage(data: AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(imageDataSampleBuffer))            var imageOrIEntation : UIImageOrIEntation?            switch UIDevice.currentDevice().orIEntation {            case UIDeviceOrIEntation.PortraitUpsIDeDown:                imageOrIEntation = UIImageOrIEntation.left            case UIDeviceOrIEntation.LandscapeRight:                imageOrIEntation = UIImageOrIEntation.Down            case UIDeviceOrIEntation.Landscapeleft:                imageOrIEntation = UIImageOrIEntation.Up            case UIDeviceOrIEntation.Portrait:                imageOrIEntation = UIImageOrIEntation.Right            default:                imageOrIEntation = UIImageOrIEntation.Right            }            var newImage = UIImage(CGImage: image!.CGImage,orIEntation: imageOrIEntation!)            UIImageWritetoSavedPhotosAlbum(newImage!,nil)        }    }}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()}}
.hasMediaType(AVMediaTypeVIDeo) } if let captureDevice = devices.first as? AVCaptureDevice { captureSession.addinput(AVCaptureDeviceinput(device: captureDevice,error: &error)) captureSession.sessionPreset = AVCaptureSessionPresetMedium captureSession.startRunning() stillimageOutput.outputSettings = [AVVIDeoCodecKey:AVVIDeoCodecJPEG] if captureSession.canAddOutput(stillimageOutput) { captureSession.addOutput(stillimageOutput) } avCaptureVIDeoPrevIEw = AVCaptureVIDeoPrevIEwLayer(session: captureSession) if let prevIEwLayer = avCaptureVIDeoPrevIEw { prevIEwLayer.bounds = CGRectMake(0.0,0.0,vIEw.bounds.size.wIDth,vIEw.bounds.size.height) prevIEwLayer.position = CGPointMake(vIEw.bounds.mIDX,vIEw.bounds.mIDY) prevIEwLayer.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill let cameraPrevIEw = UIVIEw(frame: CGRectMake(0.0,vIEw.bounds.size.height)) cameraPrevIEw.layer.addSublayer(prevIEwLayer) cameraPrevIEw.addGestureRecognizer(UITapGestureRecognizer(target: self,action:"savetoCamera:")) vIEw.addSubvIEw(cameraPrevIEw) } } // Add a selfIE button if device is capable for device in devices { if device.position == AVCaptureDeviceposition.Front { // Add selfIE button println("selfIE capable") } }}overrIDe func vIEwWillLayoutSubvIEws() { if avCaptureVIDeoPrevIEw != nil { // OrIEntation if (avCaptureVIDeoPrevIEw!.connection.supportsVIDeoOrIEntation == true) { avCaptureVIDeoPrevIEw!.connection.vIDeoOrIEntation = interfaceOrIEntationToVIDeoOrIEntation(UIApplication.sharedApplication().statusbarOrIEntation) } // Frame avCaptureVIDeoPrevIEw!.bounds = CGRectMake(0.0,vIEw.bounds.size.height) avCaptureVIDeoPrevIEw!.position = CGPointMake(vIEw.bounds.mIDX,vIEw.bounds.mIDY) avCaptureVIDeoPrevIEw!.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill }}func interfaceOrIEntationToVIDeoOrIEntation(orIEntation: UIInterfaceOrIEntation) -> AVCaptureVIDeoOrIEntation { switch orIEntation { case UIInterfaceOrIEntation.Portrait: return AVCaptureVIDeoOrIEntation.Portrait case UIInterfaceOrIEntation.PortraitUpsIDeDown: return AVCaptureVIDeoOrIEntation.PortraitUpsIDeDown case UIInterfaceOrIEntation.Landscapeleft: return AVCaptureVIDeoOrIEntation.Landscapeleft case UIInterfaceOrIEntation.LandscapeRight: return AVCaptureVIDeoOrIEntation.LandscapeRight default: return AVCaptureVIDeoOrIEntation.Portrait }}func savetoCamera(sender: UITapGestureRecognizer) { if let vIDeoConnection = stillimageOutput.connectionWithMediaType(AVMediaTypeVIDeo) { stillimageOutput.captureStillimageAsynchronouslyFromConnection(vIDeoConnection) { (imageDataSampleBuffer,error) -> VoID in var image = UIImage(data: AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(imageDataSampleBuffer)) // this is not working var orIEntation : UIImageOrIEntation? switch UIApplication.sharedApplication().statusbarOrIEntation.rawValue { case 1: orIEntation = UIImageOrIEntation.Up case 3: orIEntation = UIImageOrIEntation.left case 4: orIEntation = UIImageOrIEntation.Right default: orIEntation = UIImageOrIEntation.Up } let newImage = UIImage(CGImage: image?.CGImage,scale: 1.0,orIEntation: orIEntation!) UIImageWritetoSavedPhotosAlbum(newImage,nil,nil) } }}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}}
解决方法 编辑,这不适用于使用前置摄像头拍摄的照片,它们在原生照片应用程序中显示正常,但在Mac上的照片中共享或从parse.com加载时不能显示.

感谢@XJones在这里回答Why does AVCaptureVideoOrientation landscape modes result in upside down still images?

总结

以上是内存溢出为你收集整理的ios – AVMediaTypeVideo捕获静止图像方向全部内容,希望文章能够帮你解决ios – AVMediaTypeVideo捕获静止图像方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1046551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存