ios - Kingfisher 3.0 iOS swift RoundCornerImageProcessor 白色背景

标签 ios swift kingfisher

这是我用来设置用户图像的代码,它非常适合实际获取和设置图像。我得到了图片的白色轮廓。知道如何使它透明吗?

let processor = RoundCornerImageProcessor(cornerRadius: 50)
self.userPhoto.backgroundColor = Colors.accent
self.userPhoto.kf.setImage(with: url, placeholder: UIImage(named: "ic_camera_alt_48pt"), options: [.processor(processor)])

50 的示例 enter image description here

最佳答案

原始图像的格式不支持透明度(即 JPEG)。您必须在缓存之前将图像转换为可执行的图像(即 PNG)。

来自Kingfisher Cheat Sheet :

By default (DefaultCacheSerializer), Kingfisher will respect the input image format and try to keep it unchanged. However, there are some exceptions. A common case is that when you using a RoundCornerImageProcessor, you may always want the alpha channel. If your original image is jpg, you may want to set the png serializer instead:

let roundCorner = RoundCornerImageProcessor(cornerRadius: 20)
imageView.kf.setImage(with: url, 
    options: [.processor(roundCorner), 
              .cacheSerializer(FormatIndicatedCacheSerializer.png)]
)

关于ios - Kingfisher 3.0 iOS swift RoundCornerImageProcessor 白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44675108/

相关文章:

iOS7-iPhone 呈现 View Controller - UIPickerView

ios - 尝试在 Here Explore for iOS 中为 map 标记创建 MapImage 实例会出现奇怪的错误

ios - 在 SpriteKit 中触摸移动的 Sprite

IOS Swift Kingfisher Resize 处理器结果图像模糊

ios - 使用 Kingfisher 将 URL 加载到数组中

ios - 使用 Kingfisher 在 imagePickerController 中设置图像

iphone - Objective-C UIRefreshControl 不工作

iOS Swift 如何监控 UIViewController 生命周期

ios - Swift 中的解析和 GMaps iOS SDK 不兼容?

ios - 在 swift 类中调用目标 block