문제 설명
UIImagePNGRepresentation() 내 UIImage 회전 (UIImagePNGRepresentation() rotate my UIImage)
이미지는 UIImagePickerViewController
에서 가져옵니다.
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
print("1: \(image)")
if let data = UIImagePNGRepresentation(image) {
print("2: \(UIImage(data: data))")
}
}
}
결과는 다음과 같습니다.
1: 크기 {3024, 4032} 방향 3 축척 1.000000 2: 선택 사항(크기 {4032, 3024} 방향 0 크기 1.000000)
UIImagePNGRepresentation()
이 이미지의 방향을 변경하는 이유는 무엇입니까? 이를 방지하는 방법은 무엇입니까?
참조 솔루션
방법 1:
In first case your image orientation is UIImageOrientationRight
(value 3). In second case the orientation is UIImageOrientationUp
value 0 which is default.
You can fix the orientation issues while converting images to data and vice versa.
Please se this answer iOS UIImagePickerController result image orientation after upload
Update: You can change fix its orientation with code in above link. It will not affect the uploading procedure.
If you are not bothered about the data format, you can convert it to JPEG format
like if let data = UIImageJPEGRepresentation(image, 1.0) {
print("2: \(UIImage(data: data))")
}
(by Bartłomiej Semańczyk、Johnykutty)