简体   繁体   English

RGB颜色列表(例如[255,0,0])到二进制(例如b'\\ xff \\ x80 \\ x00')(用于混合器纹理缓冲区)

[英]RGB color list like [255,0,0] to binary like b'\xff\x80\x00' (for blender texture buffer)

sorry if it's a duplicate, I found a lot of pointers but no answer about the following ; 对不起,如果它是重复的,我发现了很多指针,但没有以下内容的答案;

I want to convert that kind of rgb values list : 我想转换那种rgb值列表:

rgb = [ 255,128,0 ]

to this binary format : 转换为以下二进制格式:

Brgb = b'\xff\x80\x00'

this is to feed a GL texture buffer in blender and generate a uniform texture. 这是在混合器中填充GL纹理缓冲区并生成均匀的纹理。

so far, I mean since 10mn after 3 hours clicking there and there and testing, I use this lame, but working, code : 到目前为止,我的意思是,自从3个小时点击并进行测试3个小时后的1000万开始,我使用了这个la脚,但是可以正常工作的代码:

rgb = [255,128,0]
rgb = "\\x%02X\\x%02X\\x%02X" % (rgb[0],rgb[1],rgb[2])
brgb = eval("b'%s'"%rgb)

logic.tex.source.load( brgb * (256*256),256,256)
# got this orange texture in my buffer

how would you do this properly ? 您将如何正确执行此操作? many thanks 非常感谢

Just turn the integers into bytes directly : 只需将整数直接转换为bytes

>>> rgb = [255, 128, 0]
>>> bytes(rgb)
b'\xff\x80\x00'

The sequence of integers is directly interpreted as byte values. 整数序列直接解释为字节值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 how to store bytes like b'PK\x03\x04\x14\x00\x08\x08\x08\x009bwR\x00\x00\x00\x00\x00\x00\x00 to dataframe or csv in python - how to store bytes like b'PK\x03\x04\x14\x00\x08\x08\x08\x009bwR\x00\x00\x00\x00\x00\x00\x00 to dataframe or csv in python 我如何将像 b'\\x08\\x00\\x00\\x00' 这样的 Python/socket 读取的雷达数据解码为数字 - How do I decode radar data read by Python/socket like b'\x08\x00\x00\x00' to numbers 将字符串字节转换为字节,例如 b'\x00\x01\x02' - Convert string byte to byte like b'\x00\x01\x02' 我如何在 python 中将 "\\xff\\xfet\\x00e\\x00s\\x00t\\x00" 转换为 b'\\xff\\xfet\\x00e\\x00s\\x00t\\x00"' - How can i convert "\xff\xfet\x00e\x00s\x00t\x00" into b'\xff\xfet\x00e\x00s\x00t\x00"' in python 如何在 python 中解码 b"\x80"? - How to decode b"\x80" in python? 来自python程序的配置单元查询返回输出,如“ x00e \\ x00” \\ x00” - Hive query from python program returns output like “x00e\x00”\x00" 为什么psycopg2无法插入'\\ x00'这样的字符串? - why psycopg2 can not insert string like '\x00'? 计数python中的十六进制字符串(\\ x00…\\ xff) - Count up hex string in python (\x00 …\xff) 在 python 中过滤 \\xe2\\x80\\x9e 来自 HTML 的表情符号 3 - Filter Emojis like \\xe2\\x80\\x9e from HTML in python 3 python 视频 b'\x1aE\xdf\xa3\x01\x00\x00\x00\x00\x00\x00\ - python video b'\x1aE\xdf\xa3\x01\x00\x00\x00\x00\x00\x00\
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM