当前位置:   article > 正文

python画圆角矩形_Python图像库(PIL)绘图——带渐变的圆角矩形

imagedraw渐变矩形

这是一种非常野蛮的方法,但它能完成任务。生成渐变的代码是从here中借用的。from PIL import Image, ImageDraw

def channel(i, c, size, startFill, stopFill):

"""calculate the value of a single color channel for a single pixel"""

return startFill[c] + int((i * 1.0 / size) * (stopFill[c] - startFill[c]))

def color(i, size, startFill, stopFill):

"""calculate the RGB value of a single pixel"""

return tuple([channel(i, c, size, startFill, stopFill) for c in range(3)])

def round_corner(radius):

"""Draw a round corner"""

corner = Image.new('RGBA', (radius, radius), (0, 0, 0, 0))

draw = ImageDraw.Draw(corner)

draw.pieslice((0, 0, radius * 2, radius * 2), 180, 270, fill="blue")

return corner

def apply_grad_to_corner(corner, gradient, backwards = False, topBottom = Fals

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/742940
推荐阅读
相关标签
  

闽ICP备14008679号