How to convert 24 bit RGB to 8 bit RGB

后端 未结 3 1866
离开以前
离开以前 2021-01-05 18:23

I was wondering what is the best way to convert a 24-bit RGB color (8 bits per color) into an 8-bit color (2bits Blue, 3 Green, 3 Red). I\'d like C code for doing this.

3条回答
  •  轮回少年
    2021-01-05 19:06

    Not in C but in javascript.

    encodedData = (Math.floor((red / 32)) << 5) + (Math.floor((green / 32)) << 2) + Math.floor((blue / 64));
    

    https://stackoverflow.com/a/25258278/2130509

提交回复
热议问题