take uiimageview image and convert to uiimage (swift4)

1.6k Views Asked by At

I have a image view with a photo in it. I want to take that photo and convert it it to a UIImagePNGRepresentation. In a effort to store it as core Data. What I have coded right now does no work.

    import UIKit

class editVCViewController: UIViewController {
    @IBOutlet var imageV: UIImageView!


    @IBAction func press(_ sender: Any) {


        var image = UIImage(named: self.imageV)
        var rep = UIImagePNGRepresentation(image!)

    }

}
1

There are 1 best solutions below

0
matt On BEST ANSWER

You have

var image = UIImage(named: self.imageV)

That won't compile, because imageV is an image view, not the (string) name of an image in your bundle.

Just say

var image = self.imageV.image