gpt4 book ai didi

android - setColorFilter() 和可变绘图

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:13:00 25 4
gpt4 key购买 nike

这段代码有什么问题?我一直在努力获得 dwb2 ColorFiltered 几个小时,当按下这个按钮时它只显示原始资源:(

public ButtonEx(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub

Drawable dwb = getResources().getDrawable(R.drawable.mainboard_btn_pen_colour);
Drawable dwb2 = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.mainboard_btn_extra_time1)
.copy( Bitmap.Config.ARGB_8888, true));
dwb2.setColorFilter(getResources().getColor(R.color.mod_selected), PorterDuff.Mode.MULTIPLY);

mLstDrawables.addState(new int[] {android.R.attr.state_pressed}, dwb2);
mLstDrawables.addState(StateSet.WILD_CARD, dwb);

setBackgroundDrawable(mLstDrawables);
}

最佳答案

最终解决了这个问题:

    Drawable dwb = getResources().getDrawable(R.drawable.mainboard_btn_pen_colour);
Bitmap immutable = BitmapFactory.decodeResource(getResources(), R.drawable.mainboard_btn_extra_time1);
Bitmap mutable = immutable.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(mutable);
Paint p = new Paint();
p.setColor(getResources().getColor(R.color.mod_selected));
p.setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.mod_selected), PorterDuff.Mode.MULTIPLY));
c.drawBitmap(mutable, 0.f, 0.f, p);
BitmapDrawable dwb3 = new BitmapDrawable(getResources(), mutable);

mLstDrawables.addState(new int[] {android.R.attr.state_pressed}, dwb3);
mLstDrawables.addState(StateSet.WILD_CARD, dwb);

setBackgroundDrawable(mLstDrawables);

关于android - setColorFilter() 和可变绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12133139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com