美文网首页
python 中的RGB颜色转换成10,16进制

python 中的RGB颜色转换成10,16进制

作者: 丙吉 | 来源:发表于2023-05-27 13:47 被阅读0次

有一组RGB三基色,想看看它原本的颜色,数据形如:

image.png

将它转换为10进制的,16进制的值,代码如下:

df['color_value'] = df[['R','G','B']].apply(lambda x: (x['R']<<16)|(x['G']<<8)|x['B'],axis=1)
df['color_value_hex'] = df['color_value'].apply(lambda x: hex(x))
df

转换后的数据如下:


image.png
查看pygame预定的颜色:
from pprint import pprint
import pygame as pg
pprint(pg.color.THECOLORS)
结果如下:
image.png
参考:

https://blog.csdn.net/acktomas/article/details/125856545

相关文章

网友评论

      本文标题:python 中的RGB颜色转换成10,16进制

      本文链接:https://www.haomeiwen.com/subject/finledtx.html