デバイスのカメラを使って写真を撮りたいです。画像を別のビューコントローラに渡したいのですが、画像は2番目のビューコントローラにのみ表示する必要があります。しかし、イメージはデバイスの写真ライブラリに保存する必要があります。イメージピッカーを使用してこれを達成するにはどうすればよいですか?写真を撮って別のビューコントローラに渡す方法
私が試したコードはfunc takePhoto(sender : UIButton)
{
if (UIImagePickerController.isSourceTypeAvailable(.Camera))
{
if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
imagePicker.allowsEditing = false
imagePicker.sourceType = .Camera
imagePicker.cameraCaptureMode = .Photo
presentViewController(imagePicker, animated: true, completion: {})
} else {
print("Rear camera doesn't exist Application cannot access the camera.")
}
} else {
print("Camera inaccessable Application cannot access the camera.")
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?)
{
TakenImage = image
let selectorToCall = Selector("imageWasSavedSuccessfully:didFinishSavingWithError:context:")
UIImageWriteToSavedPhotosAlbum(TakenImage!, self, selectorToCall, nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController)
{
print("User canceled image")
dismissViewControllerAnimated(true, completion: {
// Anything you want to happen when the user selects cancel
})
}
TakenImage下に表示され
は次の画像でも
コード使用されるライブラリに保存されませんthere.The画像を表示されないviewcontroller.Butに渡され 合格のために以下に示す
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
if (indexPath.row == 0)
{
let controller = self.storyboard!.instantiateViewControllerWithIdentifier("NoteDetailViewController") as! NoteDetailViewController
controller.takinPhoto = true
if(noteAlreadyEntered == true)
{
if (note != "")
{
controller.content = note
}
controller.takenImage = TakenImage
if (self.tags != "")
{
controller.tagsTextField.text = self.tags
}
}
else
{
controller.takenImage = TakenImage
if (self.tags != "")
{
controller.tagsTextField.text = self.tags
}
}
self.navigationController!.pushViewController(controller, animated: true)
}
}
このエラーの解決方法を教えてください。
を?この質問ははるかに広いです。何かを試して、あなたの質問を更新してください。 – rmaddy
intを渡すのと同じ方法で画像を渡すことができますか? –