0

I am trying to save a image over a image view with nothing in it. It does not work. Under the code below in the save() function, drawPlace.image is nil so I get the message "Image not found!".

var drawPlace = UIImageView()//The imageview

    override func viewDidLoad() {
    super.viewDidLoad()
 drawPlace.layer.addSublayer(myLayer)
    let myImage = UIImage(named: "bb.png")?.cgImage
    myLayer.frame = CGRect(x: 0, y: 0, width: 300, height: 300)
    myLayer.contents = myImage
}

func save() {
    guard let selectedImage = drawPlace.image else {
        print("Image not found!")
        return
    }
    UIImageWriteToSavedPhotosAlbum(selectedImage, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}

I have ben told I need to create a third image then save that to the photo gallery. I do not know how to do that.

Just looking to be able to save the iamgeview with the image over to the photo gallery.

  • Are you sure you post the whole code? Because in your example you get "Image not found!" because `drawPlace.image` is `nil`, which is normal because you never set an image in this UIImageView – Olympiloutre Jul 23 '19 at 00:25
  • What I am doing is trying to place a layer over the uiimageview of which I am drawing on so. Imageview on bottom image over image view and drawing on top of both. –  Jul 23 '19 at 00:38
  • Never done that I ll be honnest, but I think you ll need something more that an UIImageView outlet. Take a look at this : https://stackoverflow.com/questions/39950125/how-do-i-draw-on-an-image-in-swift – Olympiloutre Jul 23 '19 at 00:44
  • @Olympiloutre I got rid of not needed code. Hope that helps. That code I had before is not needed. –  Jul 23 '19 at 00:51
  • please read the link I sent. To me you shouldnt be simply using `UIImageView` but `UIGraphicsBeginImageContext`. look at this answer https://stackoverflow.com/a/47417969/5464805 – Olympiloutre Jul 23 '19 at 00:54

0 Answers0