我的应用程序从相机胶卷中挑选一张照片并将其存储为NSData。 当我需要在我的应用程序中显示图像时,我从NSData创建UIImage。如果原始照片是我用iPhone拍摄的肖像照片,则UIImage会左旋90度,如果原始照片是从网络,谷歌图片等保存的图像,则UIImage具有正确的方向。从NSData UIImage以错误的方向
我无法想象如何知道哪张照片需要旋转以及哪些是确定的。
任何帮助表示赞赏。
我使用的图像保存为NSData的在coredata实体代码:
asset.requestContentEditingInputWithOptions(PHContentEditingInputRequestOptions()) { (input, info) in
if let imgurl = input?.fullSizeImageURL {
let img = UIImage(data: NSData(contentsOfURL: imgurl)!)
self.gearImage = img
self.photoImageView.contentMode = UIViewContentMode.ScaleAspectFill
self.photoImageView.image = self.gearImage
}
}
然后我保存的NSData在coredata:
if self.gearImage != nil {
newItem.cgPhoto = UIImagePNGRepresentation(self.gearImage!)
}
当我必须证明我获取的图像coredata实体和:
let img = UIImage(data: self.imageData)
这就是问题所在。如果phasset fullSizeImageOrientation为null或1,则图像正常,否则旋转错误。
最大值
请张贴代码。 –