草庐IT

ios - Kingfisher 3.0 iOS swift RoundCornerImageProcessor 白色背景

coder 2023-09-10 原文

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

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 的示例

最佳答案

原始图像的格式不支持透明度(即 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/

有关ios - Kingfisher 3.0 iOS swift RoundCornerImageProcessor 白色背景的更多相关文章

随机推荐