[英]crop an image taken with the camera in swift
I have an app where the user can take a picture, but i need save only the area of the UIView that i used as a mask (with a clear background), when i try to do the cropping this is doing it wrong, i suspect that the image is bigger than the screen and the cropped area it's working good but in reference of the image instead of the screen area. 我有一个可以让用户拍照的应用程序,但是我只需要保存用作遮罩的UIView区域(背景清晰),当我尝试进行裁剪时,这是错误的,我怀疑图像大于屏幕和裁切区域,效果很好,但参考的是图像而不是屏幕区域。
This my code: (cameraFrame is the mask view) 这是我的代码:(cameraFrame是蒙版视图)
if let videoConnection = output.connectionWithMediaType(AVMediaTypeVideo) {
output.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(sampleBuffer, error) in
var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
var dataProvider = CGDataProviderCreateWithCFData(imageData)
var cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, kCGRenderingIntentDefault)
var cropped = CGImageCreateWithImageInRect(cgImageRef, self.cameraFrame.frame)
self.imagen = UIImage(CGImage: cropped, scale: 1.0, orientation: UIImageOrientation.Right)
self.performSegueWithIdentifier("aImagen", sender: self)
})
}
I am using following pod 我正在使用以下吊舱
https://github.com/AlexLittlejohn/ALCameraViewController https://github.com/AlexLittlejohn/ALCameraViewController
usage 用法
let croppingEnabled = true
let cameraViewController = ALCameraViewController(croppingEnabled: croppingEnabled) { image in
// Do something with your image here.
// If cropping is enabled this image will be the cropped version
}
presentViewController(cameraViewController, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.