UIImagePNGRepresentation() 내 UIImage 회전 (UIImagePNGRepresentation() rotate my UIImage)


문제 설명

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ńczykJohnykutty)

참조 문서

  1. UIImagePNGRepresentation() rotate my UIImage (CC BY‑SA 2.5/3.0/4.0)

#uiimagepickercontroller #swift #iOS






관련 질문

UIImagePickerController 닫기 (Dismiss UIImagePickerController)

UIImagePickerController에서 이미지 크기 조정이 작동하지 않음 (Resizing an image from UIImagePickerController not working)

사진 촬영 후 사진 사용 또는 재촬영을 선택할 수 없습니다. (After Taking Picture cannot select Use Photo or Retake)

런타임 오류를 제공하는 UIImagePicker (UIImagePicker giving runtime error)

Swift:UIImagePickerController에서 버튼의 텍스트를 변경하는 방법은 무엇입니까? (Swift: how to change the text of buttons in UIImagePickerController?)

iOS 9에서 UIImagePickerController가 이미지를 선택하지 않음 (UIImagePickerController not picking image in iOS 9)

UIImagePNGRepresentation() 내 UIImage 회전 (UIImagePNGRepresentation() rotate my UIImage)

UIImagePickerController에서 편집 사각형을 구성할 수 있습니까? (Can we config edit rectangle in UIImagePickerController)

imagePickerController를 닫는 방법? (how to close imagePickerController?)

카메라 사용 설명/사진 라이브러리 사용 설명을 추가해도 경고가 표시되지 않음 (Not showing alert even when I add Camera Usage Description / Photo Library Usage Description)

UIImagePIcker를 통해 "JPG", "PNG" 및 "JPEG" 이미지만 선택할 수 있는 방법이 있습니까? (Is there any way by which I can select only "JPG", "PNG" and "JPEG" images through UIImagePIcker)

사진 라이브러리 Swift에 비디오 저장 (Save video in Photo Library Swift)







코멘트