PIL ellipse函数画椭圆

问题描述

PIL ellipse函数画椭圆




解决方案

函数原型ellipse(xy, fill=None, outline=None)

该函数用于画椭圆。

第一参数为椭圆的外切矩形, 当外切矩形是正方形时,形状为圆。xy指(x1, y1, x2, y2)可以看成是(left, top, right, bottom)

第二、三参数为填充颜色和线条颜色。

在这里插入图片描述

from PIL import Image
from PIL import ImageDraw

image = Image.open('1.jpg')
draw = ImageDraw.Draw(image)

draw.ellipse((590, 260, 620, 290), 'red')
image.show()

在这里插入图片描述




所有颜色:

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.colors as colors
import math


fig = plt.figure()
ax = fig.add_subplot(111)

ratio = 1.0 / 3.0
count = math.ceil(math.sqrt(len(colors.cnames)))
x_count = count * ratio
y_count = count / ratio
x = 0
y = 0
w = 1 / x_count
h = 1 / y_count

for c in colors.cnames:
    pos = (x / x_count, y / y_count)
    ax.add_patch(patches.Rectangle(pos, w, h, color=c))
    ax.annotate(c, xy=pos)
    if y >= y_count-1:
        x += 1
        y = 0
    else:
        y += 1

plt.show()

在这里插入图片描述




参考文献

  1. 几何图形的绘制与文字的绘制(ImageDraw类详解)
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XerCis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值