user8105388
user8105388

Reputation:

take uiimageview image and convert to uiimage (swift4)

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!)

    }

}

Upvotes: -1

Views: 1714

Answers (1)

matt
matt

Reputation: 534893

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

Upvotes: 3

Related Questions