Kingfisher 3.0 iOS swift RoundCornerImageProcessor white background

不想你离开。 提交于 2019-12-23 19:26:51

问题


This is the code that I am using to set the user image which works great to actually get and set the image. I get a white outline to the picture. Any idea how to make this transparent?

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)])

Example with 50


回答1:


The format of the original image doesn't support transparency (i.e. JPEG). You must convert the image to one that does (i.e. PNG) prior to caching.

From the 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)]
)



回答2:


You don't need the RoundCornerImageProcessor

self.userPhoto.layerCornerRadius = 50
self.userPhoto.clipsToBounds = true
self.userPhoto.backgroundColor = Colors.accent
self.userPhoto.kf.setImage(with: url, placeholder: UIImage(named: "ic_camera_alt_48pt"))


来源:https://stackoverflow.com/questions/44675108/kingfisher-3-0-ios-swift-roundcornerimageprocessor-white-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!