ios - PNG图像未写入画廊
问题描述
在我的 IBACTION 上使用以下代码将我的 UIImageview > UIImage > PNG 放入照片中
但是,当我按我的 IBACTION 时,图像不在我的图库中
UIGraphicsBeginImageContextWithOptions(self.theView.bounds.size, view.isOpaque, 0)
theView.layer.render(in: UIGraphicsGetCurrentContext()!)
let theCapturedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let data = theCapturedImage!.pngData()
let url = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(NSUUID().uuidString+".dat")
do {
try data!.write(to: url!, options: [])
} catch let e as NSError {
print("Error! \(e)");
return
解决方案
不要将数据写入临时目录,而是在do
块内尝试:
let image = UIImage(data: data)
UIImageWriteToSavedPhotosAlbum(data, nil, nil, nil)
请记住,通过Privacy - Photo Library Usage Description
在info.plist
.
推荐阅读
- powershell - 从 PowerShell 脚本返回退出代码
- javascript - 仅使用 jQuery 和 plotly.js 绘制新的下拉选择
- angular - 为什么我遇到“无法绑定到 x”错误?
- javascript - 在javascript“类”中定义变量
- android - IntentService 用于后台位置更新
- javascript - DOM 操作是异步的(当使用 getElementById 或 appendChild 等浏览器提供的 API 时)?
- bash - 如何调试用“exec”调用的 shell 脚本?
- c++ - C++ 重载解析查询
- javascript - 在Javascript中将具有01值的数字输入到toString
- polymer-1.0 - 多路径对象数组变异