Upcoming SlideShare
×

# Color filters for the dummies

2,916 views

Published on

Published in: Technology
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
2,916
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
8
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Color filters for the dummies

1. 1. ColorFilters For The Dummies CodeAndroid Leong Hean Hong 31th Oct 2009 (CC) BY
2. 2. Overview1. What is bitmap?2. What is a ColorFilter?3. ColorMatrixColorFilter4. LightingColorFilter5. PorterDuffColorFilter
3. 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. 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
5. 5. ColorMatrixColorFilter● Apply mathematical operations by multiplying a 4x5 matrix
6. 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. 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
8. 8. Q&A