您好我是pdfkit
和iOS应用程序的新用户,我想用设备拍照,然后将图像转换为pdf。用相机拍照并将其保存在相机胶卷上工作完全正常,问题是当我想从该图像创建pdf时它需要图像的名称,我怎么能找到它?
另一个问题是可以用pdfkit
实现任何pdf编辑器来编辑图像吗?
感谢任何帮助。以下是我的imagePickerController
代码。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
if (Mylibrary)
{
}
else
{
UIImageWriteToSavedPhotosAlbum(pickedImage!, nil, nil, nil);
let image = UIImage(named: "????") //the problem is here
let newPage = PDFPage(image: image!)
}
picker.dismiss(animated: true, completion: nil)
}
答案 0 :(得分:1)
由于图像已存储在pickedImage
变量中,因此无需实例化新图像。您只需要使用PDFPage
初始化新的pickedImage
对象。使用ImageKit
编辑图像,然后再使用它初始化新的PDFPage
对象。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
guard let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else { return }
// Adds pickedImage to the user’s Camera Roll album.
UIImageWriteToSavedPhotosAlbum(pickedImage, nil, nil, nil)
// Creates a new PDFPage object and initializes it with pickedImage.
let newPage = PDFPage(image: pickedImage)
dismiss(animated: true, completion: nil)
}