Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
よしなに頑張る画像ロードの話 / image load mettya tsurai
Search
Yoshihiro WADA
June 18, 2019
Programming
2
470
よしなに頑張る画像ロードの話 / image load mettya tsurai
2019/06/18に開催されたPotatotips #62にて発表したスライドです
Yoshihiro WADA
June 18, 2019
Tweet
Share
More Decks by Yoshihiro WADA
See All by Yoshihiro WADA
Gradleの実行環境設定を見直す
e10dokup
0
720
Firebase App Distributionのテストアプリ配信を試しやすくする
e10dokup
0
500
アプリに署名する 〜GitHub ActionsでのCIも見据えて〜
e10dokup
0
1.1k
Profileable buildでより正確なパフォーマンスを掴む
e10dokup
0
680
[DroidKaigi 2021] メディアアクセス古今東西 / Now and Future of Media Access
e10dokup
0
3.2k
今更「dp」を考える / Let's think about "dp" now
e10dokup
0
5.4k
1から学ぶAndroidアプリデバッグ - アプリの動作を追いかけよう / Learn Android application debugging from the scratch - track apps' behaviors
e10dokup
10
3k
Guide to background processingを読んでみる / Reading "Guide to background processing"
e10dokup
0
250
WorkManager Stableに向けての所感
e10dokup
2
420
Other Decks in Programming
See All in Programming
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Arm移行タイムアタック
qnighy
0
320
subpath importsで始めるモック生活
10tera
0
300
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
890
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
cmp.Or に感動した
otakakot
2
140
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
A Modern Web Designer's Workflow
chriscoyier
693
190k
How STYLIGHT went responsive
nonsquared
95
5.2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Designing the Hi-DPI Web
ddemaree
280
34k
Documentation Writing (for coders)
carmenintech
65
4.4k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Transcript
Yoshihiro Wada a.k.a. @e10dokup Potatotips #62 - 2019/06/18
Yoshihiro Wada a.k.a. @e10dokup CyberAgant Inc. / Ameba Ameba
None
1 URL 2 3 3.5
bumptech/glide square/picasso Image Loading Library bumptech/glide 4.9.0 ConstraintLayout
1 URL
GlideApp.with(this) .load(/* Image URL */) .placeholder(/* Placeholder Drawable */) .error(/*
Error Drawable */) .into(/* Target ImageView */)
2
ConstraintLayout XML ImageView <ImageView android:id=“@+id/image_view” android:layout_width="0dp" android:layout_height=“0dp” app:layout_constraintDimensionRatio="H,3:2" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf=“parent" />
centerCrop GlideApp.with(this) .load(/* Image URL */) .placeholder(/* Placeholder Drawable */)
.error(/* Error Drawable */) .centerCrop() .into(/* Target ImageView */)
XML BindingAdapter <ImageView android:id=“@+id/image_view” android:layout_width="0dp" android:layout_height=“0dp” app:layout_constraintDimensionRatio="H,3:2" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf=“parent”
app:url=“@{imageUrl}” />
BindingAdapter BindingAdapter @BindingAdapter(“url") internal fun ImageView.loadImage(url: String?) { if (url
== null) { setImageDrawable(null) return } GlideApp .with(this) .load(url) .centerCrop() .into(this) }
3
DimensionRatio
API URL BindingAdapter DimensionRatio 3 <ImageView android:id=“@+id/image_view” android:layout_width="0dp" android:layout_height=“0dp” app:width=“@{imageWidth}”
app:height=“@{imageHeight}” app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf=“parent” app:url=“@{imageUrl}” />
width/height dimensionRatio BindingAdapter layout_constraintDimensionRatio ConstraintLayout BindingAdapter 3 @BindingAdapter(“width”, “height”) internal
fun ImageView.setAspectRatio(width: Int, height: Int) { (layoutParams as ConstraintLayout.LayoutParams).dimensionRatio = “h,${width}:${height}” }
glide RequestListener Drawable requestLayout() onMeasure() 3.5
3.5 override fun onResourceReady( resource: Drawable?, model: Any?, target: Target<Drawable>?,
dataSource: DataSource?, isFirstResource: Boolean ): Boolean { resource ?: return false val width = resource.intrinsicWidth.toFloat() val height = resource.intrinsicHeight.toFloat() aspectRatio = width / height requestLayout() return false }
3.5 override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { aspectRatio?.let {
// ݱঢ়ͷԣ෯Λऔಘ͠ɺ৽نʹΞεϖΫτൺΛөͨ͠αΠζʹΓସ͑Δ val width = MeasureSpec.getSize(widthMeasureSpec) val w = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY) val h = MeasureSpec .makeMeasureSpec((width / it).toInt(), MeasureSpec.EXACTLY) super.onMeasure(w, h) return } super.onMeasure(widthMeasureSpec, heightMeasureSpec) }
4
*NBHF7JFX *NBHF7JFX *NBHF7JFX
Load Bitmap Glide CenterCrop() Transformation Transformation 4:2 2 ->
-> Transformation
• override fun updateDiskCacheKey(messageDigest: MessageDigest) equals() / hashCode() • override
fun transform( pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int ): Bitmap toTransform Bitmap BitmapTransformation
override fun transform( pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight:
Int ): Bitmap { val width = toTransform.width val height = toTransform.height aspectRatio = width / height return when { aspectRatio >= 2 -> // 2:5 ΑΓԣ cropWidth(pool, toTransform, imageWidth, imageHeight) else -> // ͦΕҎ֎ͷͱ͖ɺͦͷ··BitmapΛฦ٫ toTransform } }
private fun transform( pool: BitmapPool, toTransform: Bitmap, width: Int, height:
Int ): Bitmap { val croppedWidth = (width * 0.5).toInt() return TransformationUtils.centerCrop( pool, toTransform, trimmedWidth, height ) }
None
:pray: