提问人:Harry McGovern 提问时间:1/29/2018 最后编辑:Harry McGovern 更新时间:2/20/2018 访问量:43
保存在 iPad 上的图像在任一面都带有黑边
Image saved on iPad is Letterboxed either side
问:
当我在 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赞
KNS user1097323
2/19/2018
#1
如果映像未正确保存到磁盘,则表示映像已损坏。保存图像时,请指定格式。此外,如果您要添加某些属性,例如 alpha 或灰色或白色,则应进行验证。在 Imagepicker Controller 回调中,检查数据是否正确,并尝试将 image 设置为某个 imageview。您的回电未正确保存数据。
评论