You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
After photo capture I need to crop image by layer rect. Presset option is .photo. `func capturePhoto(_ blockCompletion: @escaping blockCompletionCapturePhoto) {
let connectionVideo = self.stillCameraOutput.connection(withMediaType: AVMediaTypeVideo)
connectionVideo?.videoOrientation = AVCaptureVideoOrientation.orientationFromUIDeviceOrientation(UIDevice.current.orientation)
self.stillCameraOutput.captureStillImageAsynchronously(from: connectionVideo) { (sampleBuffer: CMSampleBuffer?, err: Error?) -> Void in
if let err = err {
blockCompletion(nil, err as NSError?)
}
else
{
if let sampleBuffer = sampleBuffer, let dataImage = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
{
var image = CIImage(data: dataImage)
let outputRect = self.previewLayer?.metadataOutputRectOfInterest(for: (self.previewLayer?.bounds)!)
var takenCGImage = CIContext(options: nil).createCGImage(image!, from: (image?.extent)!)
let width = CGFloat((takenCGImage?.width)!)
let height = CGFloat((takenCGImage?.height)!)
let cropRect = CGRect(x: outputRect!.origin.x * width, y: outputRect!.origin.y * height, w: outputRect!.size.width * width, h: outputRect!.size.height * height)
var cropCGImage = takenCGImage!.cropping(to: cropRect)
let imgOrientation: UIImageOrientation?
if self.cameraDevicePosition == .back
{
imgOrientation = .right
}
else
{
imgOrientation = .leftMirrored
}
let finalImage = UIImage(cgImage: cropCGImage!, scale: 1, orientation: imgOrientation!)
blockCompletion(finalImage, nil)
}
else
{
blockCompletion(nil, nil)
}
}
}`
This operation is very slow. Can I do it faster?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
After photo capture I need to crop image by layer rect. Presset option is .photo. `func capturePhoto(_ blockCompletion: @escaping blockCompletionCapturePhoto) {
let connectionVideo = self.stillCameraOutput.connection(withMediaType: AVMediaTypeVideo)
connectionVideo?.videoOrientation = AVCaptureVideoOrientation.orientationFromUIDeviceOrientation(UIDevice.current.orientation)
This operation is very slow. Can I do it faster?
The text was updated successfully, but these errors were encountered: