我正在使用AVFoundation拍照,但是当我拍照时,回来的照片比我拍的照片更大。
有谁知道为什么会这样?
我让相机处于横向模式。
下面是我拍摄图像然后将其分配给新变量的代码。
var cropArea:CGRect{
get{
let factor = backImage.image!.size.width/view.frame.width
let scale = CGFloat(1)
let imageFrame = viewFinder.imageFrame()
let x = (cropAreaView.frame.origin.x - imageFrame.origin.x) * scale * factor
let y = (cropAreaView.frame.origin.y - imageFrame.origin.y) * scale * factor
let width = cropAreaView.frame.size.width * scale * factor
let height = cropAreaView.frame.size.height * scale * factor
return CGRect(x: x, y: y, width: width, height: height)
}
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
if let imageData = photo.fileDataRepresentation() {
print(imageData)
image = UIImage(data: imageData)
backImage.image = image
let croppedCGImage = self.backImage.image?.cgImage?.cropping(to: self.cropArea)
let croppedImage = UIImage(cgImage: croppedCGImage!)
self.pictureView.image = croppedImage