ios - Capturing a picture in Landscape mode with AVCapture -
currently have ios app set in landscape mode when run. camera preview in view in landscape, when take photo taking them in portrait mode. wondering how can capture image in landscape mode only. below code camera preview , takephoto functions.
override func viewwillappear(animated: bool) { let devices = avcapturedevice.deviceswithmediatype(avmediatypevideo) device in devices { if device.position == avcapturedeviceposition.back { { let input = try avcapturedeviceinput(device: device as! avcapturedevice) if capturesession.canaddinput(input){ capturesession.addinput(input) sessionoutput.outputsettings = [avvideocodeckey: avvideocodecjpeg] if capturesession.canaddoutput(sessionoutput){ capturesession.addoutput(sessionoutput) capturesession.startrunning() previewlayer = avcapturevideopreviewlayer(session: capturesession) previewlayer.videogravity = avlayervideogravityresizeaspectfill previewlayer.connection.videoorientation = avcapturevideoorientation.landscaperight cameraview.layer.addsublayer(previewlayer) previewlayer.position = cgpoint(x: self.cameraview.frame.width / 2, y: self.cameraview.frame.height / 2) previewlayer.bounds = cameraview.frame } } } catch{ print("error") } } } } @ibaction func takephoto(sender: uibutton) { tags = tags + 1 tagsfired.text = "tags fired \(tags)" if let videoconnection = sessionoutput.connectionwithmediatype(avmediatypevideo){ sessionoutput.capturestillimageasynchronouslyfromconnection(videoconnection, completionhandler: { buffer, error in let imagedata = avcapturestillimageoutput.jpegstillimagensdatarepresentation(buffer) uiimagewritetosavedphotosalbum(uiimage(data: imagedata)!, nil, nil, nil) }) } }
was able find fix via rotating uiimage in swift
needed convert uiimage cgimage
http://wiki.hawkguide.com/wiki/swift:_convert_between_cgimage,_ciimage_and_uiimage
Comments
Post a Comment