ios - 为什么 UIImagePickerController 中的图像尺寸大于原始尺寸?
问题描述
我试图在 这里阅读类似的问题,但它不能解决我的问题,因为这里的解决方案已被弃用。
所以我有一张图片,画廊的大小只有 57 Kb。我希望用户从他们的图库中挑选一张图片,但问题是,从图库中挑选的图片远大于磁盘中的原始图片,从 57 Kb 变为 560 Kb。这是我使用的代码
func showChooseImageFromGalleryAlert() {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = false
let actionSheet = UIAlertController(title: "Choose Poster", message: "Choose your best poster", preferredStyle: .actionSheet)
let actionPhotoLibrary = UIAlertAction(title: "Choose From Gallery gallery", style: .default) { (action) in
imagePickerController.sourceType = .photoLibrary
imagePickerController.modalPresentationStyle = .fullScreen
self.present(imagePickerController, animated: true, completion: nil)
}
let actionCancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
actionSheet.addAction(actionPhotoLibrary)
actionSheet.addAction(actionCancel)
actionSheet.view.tintColor = UIColor(named: ColorName.BRAND_COLOR)
self.present(actionSheet, animated: true, completion: nil)
}
结果在这里
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image = info[.originalImage] as? UIImage else {
picker.dismiss(animated: true, completion: nil)
return
}
print("check size in Kb: \(getImageSizeInkB(image: image)!) Kb")
// the image is far larger than original image in here
// it becomes 560 Kb. 10 times bigger
picker.dismiss(animated: true, completion: nil)
}
我可以得到与原始图像相同的尺寸吗?
解决方案
推荐阅读
- javascript - 如何在javascript中访问另一个窗口上的localstorage
- ansible - Ansible - 获取值的索引并将其替换为 jinja 模板
- java - 如何为 Spring Kafka Listener 创建集成测试
- spring-boot - 在使用子表值中的@JoinColumn 的 OneToMany 关系中更新而不是插入 saveAll() 方法?
- java - 如何使用具有相同名称的表单字段?
- autodesk-forge - Autodesk Forge Viewer v7 - setThemingColor
- c++ - 当我使用 CHAR_INFO 结构时,控制台无缘无故地改变颜色
- android - 调用函数并将参数从 Kotlin 传递给 Flutter
- c# - 使用类型动态返回 null 的枚举
- python - “NOT NULL 约束失败:small_small_hr_staffprofile.data”