Android: Color To Int conversion

前端 未结 5 1151
时光说笑
时光说笑 2020-12-06 03:56

This might be a stupid question but I\'m surprised that Paint class has no setColor(Color c) method. I want to do the following:

pu         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 04:39

    All the methods and variables in Color are static. You can not instantiate a Color object.

    Official Color Docs

    The Color class defines methods for creating and converting color ints.

    Colors are represented as packed ints, made up of 4 bytes: alpha, red, green, blue.

    The values are unpremultiplied, meaning any transparency is stored solely in the alpha component, and not in the color components.

    The components are stored as follows (alpha << 24) | (red << 16) | (green << 8) | blue.

    Each component ranges between 0..255 with 0 meaning no contribution for that component, and 255 meaning 100% contribution.

    Thus opaque-black would be 0xFF000000 (100% opaque but no contributions from red, green, or blue), and opaque-white would be 0xFFFFFFFF

提交回复
热议问题