【发布时间】:2018-02-26 00:59:39
【问题描述】:
当 Image 数据返回并应用到 UIImage 时,如果数据来自相机,则图像看起来旋转了 90 度。
我尝试添加
extension UIImage {
func correctlyOrientedImage() -> UIImage {
if self.imageOrientation == UIImageOrientation.up {
return self
}
UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)
self.draw(in: CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: self.size.width, height: self.size.height))
)
let normalizedImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext();
return normalizedImage;
}
}
在我的代码中,我检查我是否为特定用户保存了数据,如果有,我将图像数据加载到 profile_image,一个 UIImageView。
//profile_image
if let profile_imager = UserDefaults.standard.object(forKey: String(UserID)) as? Data {
let data = UserDefaults.standard.object(forKey: String(UserID)) as? Data
print("profile_imager: \(profile_imager)")
profile_image.image = UIImage(data: data!)
profile_image.backgroundColor = .white
}
我将如何正确使用正确的OrientedImage
谢谢
【问题讨论】:
-
如果您拍摄自拍图像,它将旋转 90 度。因此,如果您在拍摄图像时想要它的外观,那么您必须旋转它以保留。
-
@AmirKhan 我明白,但我需要知道它是否确实旋转了,因为图像可能来自画廊或网络(Facebook)
标签: ios swift3 uiimageview xcode8