当我从 UIImagePicker 获取具有透明背景的 PNG 图像时,它会插入具有透明背景的图像,如下所示:
当我设置时:
imagePicker.allowsEditing = true
Run Code Online (Sandbox Code Playgroud)
它允许我在 UIImagePicker 提供的视图中按预期进行裁剪
但是当我按“选择”时,它会返回黑色图像而不是透明背景,如下所示:
两个结果之间唯一的变化是设置
imagePicker.allowsEditing = true
Run Code Online (Sandbox Code Playgroud)
并在应用程序中裁剪图像。
有没有办法保持透明度或至少在裁剪时将黑色更改为白色?
我在互联网上搜索过,但没有看到提及这一点。
代码:
func showImagePicker() {
imagePicker.allowsEditing = true
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
compImageView?.contentMode = .scaleAspectFit
compImageView?.backgroundColor = UIColor.clear
compImageView?.image = pickedImage
}
dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 如何在忽略关联值的同时检查枚举的大小写?
以下是我使用的,但它给出了一个错误......
enum Example {
case one(value: String)
case two(otherValue: Int)
}
var test = Example.one(value: "A String")
if test == Example.one { // Gives Error
// Do Something
}
Run Code Online (Sandbox Code Playgroud)
重复的问题过于复杂.