你如何在 Android 中给位图着色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3499095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:28:58  来源:igfitidea点击:

How do you tint a bitmap in Android?

androidimagebitmap

提问by FoppyOmega

I draw a bitmap onto a canvas using the following call:

我使用以下调用在画布上绘制位图:

_playerImage = BitmapFactory.decodeResource(getResources(), R.drawable.player);

How can I now tint this image white? I'm trying to make the image flash white like in top-scrollers when an enemy is hit by a bullet.

我现在如何将这张图片染成白色?当敌人被子弹击中时,我试图使图像像顶部卷轴一样闪烁白色。

Do I need to use something other than BitmapFactory?

我需要使用 BitmapFactory 以外的其他东西吗?

回答by Romain Guy

You can use a ColorFilteron your Paintwhen you draw the bitmap.

你可以使用ColorFilter你的Paint当你画的位图。