【问题标题】:Convert 8 bit color to 24 bit color将 8 位颜色转换为 24 位颜色
【发布时间】:2022-11-25 05:03:43
【问题描述】:

我想知道我是否可以将 8 位 RGB 颜色(1 字节 = 单色)转换为 24 位 RGB 颜色((8 位 = 红色,8 位 = 绿色,8 位 = 蓝色)= 单色)。有什么办法可以做到吗? (我不介意只有 256 种颜色)。另外,如果可能的话,它可以用 Python 写成公式/函数吗?

【问题讨论】:

    标签: colors byte bit


    【解决方案1】:
    def convert_8_to_24(byte):
        byte = int(byte, 16)
        red = (byte >> 5) * 32
        green = ((byte & 28) >> 2) * 32
        blue = (byte & 3) * 64
        return (red, green, blue)
    
    def convert_24_to_8(red, green, blue):
        byte = (floor((red / 32)) << 5) + (floor((green / 32)) << 2) + floor((blue / 64))
        byte = hex(byte)[2:]
        if len(byte) == 1:
            byte = "0" + byte
        return byte
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多