0

I am new to swift. I am working on project in which my requirement is that I want to select image from photo library or take photo from camera and after selecting image I want to draw on that image for highlighting some part of image.

I searched a lot and I found some links which I am sharing with you in those link there are too many extra things so I am not able to understand how to take only image draw functionality from that project:

[https://github.com/eventtus/photo-editor]

I did't able to try because I this project there are too many things

So if anyone have simple demo app or reference link or any other solutions for the same then please help me.

Meister96Fels
  • 508
  • 1
  • 8
  • 26
Vishal Parmar
  • 615
  • 4
  • 31

1 Answers1

2

To load an Image from the photo library, you can do this:

func openSelectImage(type: UIImagePickerController.SourceType) {
    if UIImagePickerController.isSourceTypeAvailable(type) {
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = type
        present(imagePicker, animated: true, completion: nil)
    }
}

Just call this method and the Image Picker will appear. Of course you have to conform to the UIImagePickerControllerDelegate. So you do something like this:

extension MyAwesomeViewController: UIImagePickerControllerDelegate {

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {          
            // do something with the image
            self.imageView.image = image
        }
    }
}

Now you are able to load an image into an ImageView or something. Now the part with the drawing. I think that is way too much stuff for you as you should learn the basics first. But if you are interested in learning it, here you go:

I hope that leads you into the right direction!

Happy Coding!

Tomte
  • 1,331
  • 12
  • 19