Help us understand the problem. What is going on with this article?

KingfisherでRoundCornerImageProcessor使うと白い背景色になる問題

More than 1 year has passed since last update.

ImageProcessor

Kingfisherは取得した画像を編集してから適用するImageProcessorがある

let cirlceImageProcessor = RoundCornerImageProcessor(cornerRadius: CGFloat.greatestFiniteMagnitude)
let options: KingfisherOptionsInfo = [.processor(cirlceImageProcessor)]
setImage(with: resource, options: options)

で、こんな感じで書くと角丸を付けて表示出来る。

Simulator Screen Shot - iPhone 6 - 2017-12-13 at 23.11.22.png

背景が白くなる問題

Simulator Screen Shot - iPhone 6 - 2017-12-13 at 23.10.12.png

稀にこのような状態になることがある

原因

原因はjpgの画像はjpgでキャッシュされる為。
最初の描画時はdrawでマスク後に描画されるが、2回目移行はディスクキャッシュから取ってきてそのまま表示される。jpgは透過情報を持たないので白くなってしまう

対策

pngでキャッシュすればOK
キャッシュポリシーはcacheSerializerのオプションで指定可能

let cirlceImageProcessor = RoundCornerImageProcessor(cornerRadius: CGFloat.greatestFiniteMagnitude)
let options: KingfisherOptionsInfo = [.processor(cirlceImageProcessor), .cacheSerializer(FormatIndicatedCacheSerializer.png)]
let url = URL(string: "https://www-tc.pbs.org/wnet/nature/files/2017/09/x1WLcZn-asset-mezzanine-16x9-6kkb4dA.jpg")
iv.kf.setImage(with: url, options: options)

注意点

既にjpgでキャッシュしている場合はそっちを引いてきてしまうので注意

参考文献

https://github.com/onevcat/Kingfisher/issues/693

こちらのissueで解消しました。

noppefoxwolf
きつねすき、にんげんこわい
https://noppelab.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした