img1.rectangle(shape, fill ="# ffff33", outline ="red") img.show() 输出: 另一个示例:在这里,我们使用不同的颜色进行填充。 # importing image object from PILimportmathfromPILimportImage, ImageDraw w, h =220,190shape = [(40,40), (w -10, h -10)]# creating new Image objectimg = ...
Draw.rectangle:用于绘制矩形。 Draw.text:用于在图像上绘制文本。 应用场景 Pillow广泛应用于各种需要图像处理的场景,例如: 数据可视化 图像编辑 图标制作 文档处理 示例代码 以下是一个使用Pillow绘制矩形和文本的示例代码: 代码语言:txt 复制 from PIL import Image, ImageDraw, ImageFont # 创建一个空白图像 width...
overlay = Image.new('RGBA', img.size, TINT_COLOR+(0,)) draw = ImageDraw.Draw(overlay) # Create a context for drawing things on it. draw.rectangle(((llx, lly), (urx, ury)), fill=TINT_COLOR+(OPACITY,)) # Alpha composite these two images together to obtain the desired result. img...
img_name=info['ImageID'] base=Image.open(img_name).convert('RGBA') d=ImageDraw.Draw(base) # rectangle(xy,fill, outline) # xy给出rectangle的左上和右下的像素点坐标,fill填充,outline是pencolor。 pox_x=info['Pos_X']#识别框图片坐标x pox_y=info['Pos_Y']#识别框图片坐标x pox_h=info[...
draw = ImageDraw.Draw(image) # 在图像中心绘制一个红色矩形 rect_width, rect_height = 50, 30 left = 0 top = (height - rect_height)// 2 right = left + rect_width bottom = top + rect_height draw.rectangle([left, top, right, bottom], fill="red") ...
def draw_on_image(image_path): # 创建图像对象 image = Image.open(image_path) # 调用ImageDraw.Draw()函数,创建绘制对象 draw = ImageDraw.Draw(image) # 绘制操作 draw.line([(0, 0), (100, 100)], fill='red', width=2) draw.rectangle([(50, 50), (150, 150)], outline='...
PIL.ImageDraw.Draw(img).rectangle(xy, color)returnimg 开发者ID:kakaobrain,项目名称:autoclint,代码行数:21,代码来源:augmentations.py 示例3: NewImage ▲点赞 6▼ # 需要导入模块: import PIL [as 别名]# 或者: from PIL importImageDraw[as 别名]defNewImage(self):""" ...
The ImageDraw Module 支持2D图像The ImageDraw module provide basic 2D graphics support for Image objects. It can for example be used to create new images, annotate or retouch existing images, and togenerate graphics on the fly for web use. ...
源程序: from PIL import ImageDraw, Image # 创建一个空白图像,模式为RGB,大小为1024x800像素,颜色为纯白色 image = Image.new("RGB", (2560, 1440), (255, 255, 255)) # 创建一个绘图对象 draw = ImageDraw.Draw(image) # 计算中心位置的矩形范围 start_x = (2560 - 10) // 2 start_y = ...
draw.rectangle(box, options) Draws a rectangle. The box can be any sequence object containing either 2-tuples [ (x, y), (x, y) ] or numeric values [x,y,x,y]. It should contain two coordinates. Note that the second coordinate pair defines a point just outside the rectangle, also...