简体   繁体   English

将uiimageview图像转换为uiimage(swift4)

[英]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. 我想拍张照片并将其转换为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!)

    }

}

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. 那不会编译,因为imageV是图像视图,而不是捆绑软件中图像的(字符串)名称。

Just say 说啊

var image = self.imageV.image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM