1

I'm making a drawing app and would like the user to be able to rotate the image before posting to the NewsFeedViewController if they've drawn their image in landscape. At the moment I can rotate the image but when I post to the NewsFeedViewController it returns to the original rotation.

I've got a IBAction button working that rotates the image 90 degrees:

@IBAction func rotateImageButton(_ sender: Any) {
    photo.transform = photo.transform.rotated(by: CGFloat(M_PI_2))
}

The bit I am stuck on is how to update this rotation when uploading the image to Firebase and then pulling the rotated image down from the database to the NewsFeedViewController of the app. This is my code for posting the image atm:

 @IBAction func shareButton_TouchUpInside(_ sender: Any) {
    view.endEditing(true)
    SVProgressHUD.show(withStatus: "Waiting...")

    if let profileImg = self.selectedImage, let imageData = UIImageJPEGRepresentation(profileImg, 0.1){
        HelperService.uploadDataToServer(data: imageData, caption: captionTextView.text!, onSuccess:{
            self.clean()
        })
    } else {
        SVProgressHUD.showError(withStatus: ("Post image can't be empty"))

    }

    // tabBar is indexed where home - 0 , discover is 1 etc.
    self.tabBarController?.selectedIndex = 0
    self.tabBarController?.tabBar.isHidden = false
    self.dismiss(animated: true, completion: nil)

    }
Tessa
  • 403
  • 1
  • 5
  • 13

1 Answers1

0

By changing the transform you only rotate the way the image is shown on screen. The transform defines where pixels of your unrotated image need to end up on screen.

You need to rotate the actual image pixels instead.

Here you find several ways to do that.

meaning-matters
  • 21,929
  • 10
  • 82
  • 142