Last active
September 14, 2018 13:59
-
-
Save masaibar/2c6eb1a6e3cf38ace0e5e7b2a5961e21 to your computer and use it in GitHub Desktop.
Picassoでwrap_contentなImageViewに画像を読み込む際に縦横それぞれN倍する ref: https://qiita.com/masaibar/items/7aba5cb506fe652d49e7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScaleTransformation( | |
private val scale: Float | |
) : Transformation { | |
override fun transform(source: Bitmap?): Bitmap? { | |
source ?: return null | |
//1倍にするとcreateBitmapしてもsourceを返そうとして死ぬ | |
if (scale == 1f) { | |
return source | |
} | |
val matrix = Matrix().apply { | |
setScale( | |
scale, | |
scale | |
) | |
} | |
val result = Bitmap.createBitmap( | |
source, | |
0, | |
0, | |
source.width, | |
source.height, | |
matrix, | |
true | |
) | |
source.recycle() | |
return result | |
} | |
override fun key(): String = | |
"ScaleTransformation(scale = $scale)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Picasso.get() | |
.load(imageUrl) | |
.transform(ScaleTransformation(2f)) //← 倍率を指定 | |
.into(image_view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment