当我从iPad上的简单相机应用程序保存图像时,它会创建一个信箱形状的图像。也就是说,两边都是黑条。在iPhone上保存不会这样做。 我应该在哪里查看我的代码来纠正这个问题?
编辑: 这是我保存的代码。好像好吗?我听到你在说什么,但我看不到修复。它可以保存图像,而不是iPad上的宽图像。
func saveToCamera() {
if let videoConnection = stillImageOutput.connection(with: AVMediaType.video) {
stillImageOutput.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (CMSampleBuffer, Error) in
if let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(CMSampleBuffer!) {
if let cameraImage = UIImage(data: imageData,scale: UIScreen.main.scale) {
// ------------------- Do Shutter Blink -------------------------
let blinkWidth = cameraImage.size.width
let blinkHeight = cameraImage.size.height
print("Blink Width: \(blinkWidth)")
print("Blink Height: \(blinkHeight)")
// do actual shutter simulation
let rect = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: blinkWidth, height: blinkHeight))
let shutterView = UIView(frame: rect)
shutterView.backgroundColor = UIColor.black
self.view.addSubview(shutterView)
UIView.animate(withDuration: 0.3, animations: {
shutterView.alpha = 0
}, completion: { (_) in
shutterView.removeFromSuperview()
})
//Do shutter sound
let cameraShutterSoundID: SystemSoundID = 1108
AudioServicesPlaySystemSound(cameraShutterSoundID)
// -------------- end of blliink and shutter sound ---------------------
// Actually save the combined photo
if let nImage = self.drawCirclesOnImage(fromImage: cameraImage, targetSize: CGSize.zero) {
UIImageWriteToSavedPhotosAlbum(nImage, nil, nil, nil)
}
}
}
})
}
}
答案 0 :(得分:0)
如果图像未正确保存到磁盘,则表示图像已损坏。保存图像时指定格式。此外,如果您要添加某些属性,如alpha或灰色或白色,您应该验证。在Imagepicker控制器回调检查正确的数据,并尝试将图像设置为某些imageview。您的回叫未正确保存数据。