0

I want to add UIView (UIView had contain some images and text) in UIImageView and that imageview i want to save in my Camera Roll . so please give me some suggestion or snapcode that help me to solve this problem. Click Here For UIScreen

In my case i have one UIView and One UIImageView sticker add in the UIView and I want to merge them and ya i want image in landscape mode

Any help or suggestion can be appreciate.

Thank You.

Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49
  • check this http://stackoverflow.com/questions/30696307/how-to-convert-a-uiview-to-a-image – Jigar Apr 15 '17 at 07:34

1 Answers1

0

I had a similar task and used this code:

func getResultImage() throws -> (image: UIImage, path: URL) {
    UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
    defer {
        UIGraphicsEndImageContext()
    }
    drawHierarchy(in: self.bounds, afterScreenUpdates: true)

    guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
        throw ImageEditorViewError.noImageGenerated
    }

    guard let data = UIImagePNGRepresentation(image) else {
        throw ImageEditorViewError.noDataRepresentation
    }

    let writePath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("Image.png")

    try data.write(to: writePath)

    return (image, writePath)
}

You can remove part with writePaht, as it was specific for my task

Assume, that this code is inside your container-view and you have some views-stickers inside it

Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100