前提・実現したいこと
カメラロールから取得した画像をciimageに変換した後に、画像処理を行って、uiimageに戻してuiimageviewに表示を行なった際に90度画像が回ってしまっており、この表示を回転しないようにしたいです。
該当のソースコード
swift
1 2var imageView = UIImageView() 3var image = UIImage() 4let imageOrientation = image.imageOrientation 5 6class ViewController: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate { 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 // Do any additional setup after loading the view. 11 makeButton() 12 makeImageView() 13 14 15 } 16 17func makeButton(){ 18 let button = UIButton() 19 button.frame = CGRect(x: 0, y: 0, width: x/2, height: y/5) 20 button.backgroundColor = UIColor.red 21 button.layer.masksToBounds = true 22 button.layer.cornerRadius = 30 23 button.layer.position = CGPoint(x: x/2, y: y*0.9) 24 button.addTarget(self, action: #selector(camera), for: .touchUpInside) 25 self.view.addSubview(button) 26 27 let sendBtn = UIButton() 28 sendBtn.frame = CGRect(x: 0, y: 0, width: x/2, height: y/5) 29 sendBtn.backgroundColor = UIColor.red 30 sendBtn.layer.masksToBounds = true 31 sendBtn.layer.cornerRadius = 30 32 sendBtn.layer.position = CGPoint(x: x/2, y: 0) 33 sendBtn.addTarget(self, action: #selector(detectText), for: .touchUpInside) 34 self.view.addSubview(sendBtn) 35 } 36 37 func makeImageView(){ 38 imageView.frame = CGRect(x: 0, y: 0, width: x/1.2, height: x/1.2) 39 imageView.layer.position = CGPoint(x: x/2, y: y/2) 40 imageView.contentMode = UIView.ContentMode.scaleAspectFit 41 self.view.addSubview(imageView) 42 } 43 44 45@objc func camera(){ 46 let imagePickerController = UIImagePickerController() 47 48 imagePickerController.sourceType = .photoLibrary 49 50 imagePickerController.delegate = self 51 52 self.present(imagePickerController,animated: true,completion: nil) 53 } 54 55func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { 56 // 選択した写真を取得する 57 image = info[.originalImage] as! UIImage 58 59 let inputImage = CIImage(cgImage: image.cgImage!) 60 let myMonochromeFilter = CIFilter(name: "CIColorMonochrome") 61 myMonochromeFilter!.setValue(inputImage, forKey: kCIInputImageKey) 62 myMonochromeFilter!.setValue(CIColor(red: 0.5, green: 0.5, blue: 0.5), forKey: kCIInputColorKey) 63 myMonochromeFilter!.setValue(1.0, forKey: kCIInputIntensityKey) 64 let myOutputImage : CIImage = (myMonochromeFilter?.outputImage!)! 65 66 // ビューに表示する 67 imageView.image = UIImage(ciImage: myOutputImage, scale: image.scale, orientation: imageOrientation) 68 69 70 // 写真を選ぶビューを引っ込める 71 self.dismiss(animated: true) 72 } 73}
試したこと
ciImageをUIImageに再変換する際に、(https://qiita.com/YutoMizutani/items/de6c0f2200bdbab10624)を参考にorientationを設定しましたが、画像は90度回転したままでした。
補足情報(FW/ツールのバージョンなど)
Xcode 12.4 Swift5を使用しています。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。