[英]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.