Androidで UIImageView にローカルファイルから画像を設定したい時。
何も考えずにやるとこうなる。
val bitmap = BitmapFactory.decodeFile(file)
imageView.setImageBitmap(bitmap)
(とりあえず sampleSizeは考慮しない)
でもわざわざビットマップを生成するのも冗長だよな、と考えたりして、
imageView.setImageUri(Uri.fromFile(file))
これでいいじゃん?
だけど一応公式のリファレンスをチェックしてみたら、
This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider using
setImageDrawable(android.graphics.drawable.Drawable)
orsetImageBitmap(android.graphics.Bitmap)
andBitmapFactory
instead.
って書いてあってうわぁってなった、のでブログに記録して忘れないようにしよっと。