LoginSignup
1
0

More than 1 year has passed since last update.

【Android】Bitmapの色合い変更

Last updated at Posted at 2021-05-20

ColorMatrixを使用することで色合いが変更できる。

fun Bitmap.filter(): Bitmap {
	//例としてグレースケール変更している
	val matrix = ColorMatrix(
		floatArrayOf(
			0.33f, 0.33f, 0.33f, 0f, 0f,
			0.33f, 0.33f, 0.33f, 0f, 0f,
			0.33f, 0.33f, 0.33f, 0f, 0f,
			0f, 0f, 0f, 1f, 0f
		)
	)
	val bitmap = Bitmap.createBitmap(width, height, config)
	val paint = Paint().apply { colorFilter = ColorMatrixColorFilter(matrix) }
	Canvas(bitmap).drawBitmap(this, 0f, 0f, paint)
	return bitmap
}

以前に書いた記事でも変更できるが、色合いを変更するだけならこちらの方が簡単。

参考サイト

1
0
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
1
0