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

这是一种非常强力的方法,但它完成了工作 . 产生梯度的代码是从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, topBotto

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值