gpt4 book ai didi

ios - UIImagePickerController 将透明 PNG 视为 JPEG

转载 作者:行者123 更新时间:2023-11-30 11:41:31 26 4
gpt4 key购买 nike

这在某种程度上是建立在 question 之上的不久前,但我正在研究一种解决方案,允许用户通过 UIImagePickerController 从照片库中选择图像,如果所述图像是具有透明度的 .png,则保持透明度用于在 UIImageView 中显示的图像。

我可以使用以下步骤持续重现我的问题;

  • 导入我的 image进入我的 Mac 上的“照片”。
  • 允许我的图片通过 iCloud 同步到我的 iOS 设备上的“照片”。
  • 尝试使用以下代码在我的应用中加载我的图像;

-

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {

let png = UIImagePNGRepresentation(pickedImage)
let pngImage = UIImage(data: png!)


// TEST FILE TYPE
if let fileURL = info[UIImagePickerControllerImageURL] as? URL {
// CONSISTENTLY PRINTS PUBLIC.JPEG
print(fileURL.typeIdentifier)
}
}
}

无论出于何种原因,将图像导入照片的过程都会导致 iOS 将图像视为 JPEG,而不是 PNG,从而在 UIImageView 中测试时失去其透明度。文件名仍为 .png,但无法在应用程序中使用。

顺便说一句,如果我将我的transparent.png带入我的Xcode项目,并将我的UIImageView设置为imageView.image = UIImage(named: "newTest.png"),透明度功能完全通常情况下。

更新:这似乎是一个在 iOS 11 上重现不一致的问题。SO 和其他留言板上的其他用户已经确认了这种情况。目前,我建议的解决方法是找到一种解决方案,从外部源下载透明 PNG,而不是从用户的照片库加载。重新启动 iOS 设备似乎确实可以在一段不确定的时间内解决该问题。

最佳答案

确保 iCloud 照片库的优化 设置已关闭:

On your iPhone, iPad, or iPod touch:

  1. Tap Settings > [your name] > iCloud. If you’re using iOS 10.2 or earlier, tap Settings > iCloud.
  2. Tap Photos.
  3. Choose Optimize [device] Storage.

On your Mac:

  1. Open the Photos app and click Photos in the menu bar.
  2. Click Preferences.
  3. Go to the iCloud tab and choose a storage setting.

如果打开,您必须在关闭图像库后将图像重新添加到照片库中才能保留原始图像。

关于ios - UIImagePickerController 将透明 PNG 视为 JPEG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49242707/

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