本文整理汇总了Python中color.Color.getRGB方法的典型用法代码示例。如果您正苦于以下问题:Python Color.getRGB方法的具体用法?Python Color.getRGB怎么用?Python Color.getRGB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类color.Color
的用法示例。
在下文中一共展示了Color.getRGB方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replace_color
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import getRGB [as 别名]
def replace_color(self, color, new_color=None):
"""
Replace color with with new_color or with alpha.
"""
pixels = self.getRGB(0,0,self.width,self.height,None,0,self.width)
color1 = Color(color) #0.23
if new_color:
color2 = Color(new_color)
else:
color2 = Color(color1.r,color1.g,color1.b,0)
for i, pixel in enumerate(pixels):
if pixel == color1.getRGB():
pixels[i] = color2.getRGB()
self.setRGB(0,0,self.width,self.height,pixels,0,self.width)
return None
示例2: set_at
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import getRGB [as 别名]
def set_at(self, pos, color):
"""
Set color of a surface pixel.
The arguments represent position x,y and color of pixel.
"""
color = Color(color) #0.23
try:
self.setRGB(pos[0],pos[1],color.getRGB()) #0.23
except: #ArrayOutOfBoundsException
raise IndexError
return None
示例3: from_threshold
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import getRGB [as 别名]
def from_threshold(surface, color, threshold=(0,0,0,255)):
"""
**pyj2d.mask.from_threshold**
Return Mask from surface using a given color.
Optional threshold argument to set color range and alpha threshold.
"""
mask = Mask((surface.width, surface.height))
pixels = surface.getRGB(0,0,surface.width,surface.height,None,0,surface.width)
if threshold == (0,0,0,255):
color = Color(color) #0.23
if color.a != 255:
color = Color(color.r,color.g,color.b,255)
icolor = color.getRGB()
i = 0
for y in range(surface.height):
for x in range(surface.width):
if pixels[i] == icolor:
mask.set_at((x,y))
i += 1
else:
color = Color(color) #0.23
col = {}
for i, c in enumerate(('r','g','b')): #0.23
if threshold[i]:
col[c+'1'] = color[i] - threshold[i] - 1
col[c+'2'] = color[i] + threshold[i] + 1
else:
col[c+'1'] = color[i] - 1
col[c+'2'] = color[i] + 1
col['a'] = threshold[3] - 1
i = 0
for y in range(surface.height):
for x in range(surface.width):
if ( col['r1'] < ((pixels[i]>>16) & 0xff) < col['r2'] ) and ( col['g1'] < ((pixels[i]>>8) & 0xff) < col['g2'] ) and ( col['b1'] < ((pixels[i]) & 0xff) < col['b2'] ) and ( ((pixels[i]>>24) & 0xff) > col['a'] ):
mask.set_at((x,y))
i += 1
return mask