import UIKit
class ViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
@IBOutlet weak var pickedImaged: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func camerabuttonaction(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)
{
let imagepicker = UIImagePickerController()
imagepicker.delegate = self
imagepicker.sourceType = UIImagePickerControllerSourceType.camera;
imagepicker.allowsEditing = false
self.present(imagepicker,animated: true,completion: nil)
}
}
@IBAction func photolibraryaction(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary)
{
let imagepicker = UIImagePickerController()
imagepicker.delegate=self
imagepicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagepicker.allowsEditing = true
self.present(imagepicker,animated: true,completion: nil)
}
}
@IBAction func Saveaction(_ sender: Any) {
let imageData = UIImageJPEGRepresentation(pickedImaged.image!, 0.6)
let compressedJPEGImage = UIImage(data: imageData!)
UIImageWriteToSavedPhotosAlbum(compressedJPEGImage!, nil, nil, nil)
saveNotice()
}
// func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// pickedImaged.image = image
// self.dismiss(animated: true, completion: nil)
//
//
//
// }
// func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image:UIImage!, edit[NSObject : AnyObject]!)
// {
// self.dismiss(animated: true, completion: nil);
// }
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
pickedImaged.contentMode = .scaleAspectFit
pickedImaged.image = pickedImage
}
self.dismiss(animated: true, completion: nil)
};
func saveNotice()
{
let alertController = UIAlertController(title: "Title", message: "succesfully saved",preferredStyle: .alert)
let defaultAction = UIAlertAction(title:"OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
present(alertController,animated: true,completion: nil)
}
}
----------------------------------------------------------------------------------------------
No comments:
Post a Comment