2. Overview
1. What is bitmap?
2. What is a ColorFilter?
3. ColorMatrixColorFilter
4. LightingColorFilter
5. PorterDuffColorFilter
3. What is Bitmap?
● A 2 dimensional array of pixels
● Pixel consists of components (A, R, G, B)
● Each component can be described by an integer [0 to 255]
● Hexadecimal form: 0xAARRGGBB
○ Some libraries from some fruit company may use floating
value [0.0 ~ 1.0]
● Example
○ (1, 255, 0, 0) - Opaque red color
○ (1, 123, 123, 123) - Opaque grey color
○ (1, 0, 0, 0) - Oaque balck color
○ (128, 0, 255, 255) - 50% transparent yellow color
4. What is ColorFilter
● Change colors in a bitmap
by
○ applying mathematical operations (e.g. +, -, *, /, modulo,
AND, OR, NOT, XOR, ...)
on
■ color/alpha components of bitmap
6. LightingColorFilter
● LightingColorFilter(int mul, int add)
● Multiply RGB components by 1 color, follow by addition of
another color
● No change to alpha component
● Resultant value of each component will be pinned to [0, 255]
● Value range from 0x000000 to 0xffffff
● Examples
○ LightingColorFilter(0xff0000, 0x0000ff) = times red plus
blue
○ LightingColorFilter(0x00ff00, 0xff0000) = times green plus
red
7. PorterDuffColorFilter
● Mathematical operation on 2 bitmaps (source & destination)
● Android defines 16 types of operation (android.graphics.
PorterDuff.Mode)
● Sample code available in ApiDemos
(<sdk_folder>/samples/ApiDemos) com.example.android.
apis.graphics/Xfermodes.java