android - alpha value always resetted after color change of paint -


i'm drawing several shapes in different colors, using single instance of paint. alpha value (< 255) of each painted region same. set desired alpha value when initializing paint. however, whenever change color of paint using setcolor, alpha value of paint reset 255 (fully opaque).

the following code demonstrates issue:

mypaint.setalpha(100);  // mypaint.getalpha() returns 100, expected;  mypaint.setcolor(color.dkgray);  // mypaint.getalpha() returns 255; 

why happen? there impact on performance if forced call paint.setalpha(...) every time change paint color?

this because color using of format argb. see paint , color javadoc. need specify color rgb or set color alpha value want use. , shouldn't of performance hit if set alpha each time, if want go route.

as added example

paint.setcolor(new color(100, color.red(color.dkgray), color.green(color.dkgray), color.blue(color.dkgray))); 

if going set color dark gray better off creating color resource values want , using it.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -