LoginSignup
5
3

More than 5 years have passed since last update.

Bitmapを好きなサイズに変更

Posted at

やりたいこと

  • bitmapの大きさを固定値で指定したサイズで調整
  • bitmapの大きさ比率で指定したサイズで調整

方法

固定値

Fixed.kt
// fixedSize = 指定値
val bitmap = Bitmap.createScaledBitmap(bitmap, fixedSize, fixedSize, true)

比率

Ratio.kt
val matrix = Matrix()
matrix.postScale(0.5f, 0.5f) // 0.5倍調整
val scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)

最後の引数 filter はアンチエイリアスで補正を入れるかどうかの指定

おまけ

回転

Rotate.kt
val matrix = Matrix()
matrix.postRotate(rotate.toFloat()) // 回転値
val rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3