【swift】写真ピッカー UIImagePickerController

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .photoLibrary
imagePickerController.allowsEditing = true
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}


,UIImagePickerControllerDelegate 追加

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image:UIImage = info[UIImagePickerControllerOriginalImage]  as! UIImage
let imageData:NSData? = UIImagePNGRepresentation(image) as NSData?
picker.dismiss(animated: true, completion: nil)
}

返信を残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA