gpt4 book ai didi

ios - 如何拍照并将其传递给另一个 View Controller

转载 作者:行者123 更新时间:2023-11-28 06:37:06 24 4
gpt4 key购买 nike

<分区>

我想使用设备的相机拍照。我希望使用 segue 将图像传递到另一个 View Controller 。图像只需要在第二个 View Controller 中显示。但图像需要保存到设备的照片库中。如何使用图像选择器实现此目的?

我试过的代码如下所示

 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 被传递给下一个 View Controller 。但是图像没有出现在那里。图像也没有保存在库中

用于传递的代码如下所示

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)
}
}

如何解决这个错误?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com