Why is there bit shifting when converting to an image from an array?

匆匆过客 提交于 2019-12-06 04:20:11

I assume that you want to know why the bit-shifting and or-ing is happening. Well, you need to join the A[lpha], R[ed], G[reen], and B[lue] bytes together to form a single integer value. Pixel data is a 2D array of integer; scalar value. They are not tuples of bytes.

Example

Color: Periwinkle

A: 255 -> 11111111
R: 204 -> 11001100
G: 204 -> 11001100
B: 255 -> 11111111

Formula

Value = A << 24 | R << 16 | G << 8 | B

Bit-Math

  11111111000000000000000000000000
          110011000000000000000000
                  1100110000000000
 +                        11111111
 ---------------------------------
  11111111110011001100110011111111

Base conversion

111111111100110011001100111111112 = 429161190310

Finally

Based on the bit manipulation above, the color Periwinkle, with 100% opacity in ARGB, has a pixel value of 4,291,611,903.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!