我正在创建的PIL图像有问题。似乎灰色背景的边框边缘采用在背景顶部绘制的椭圆的颜色。
首先,我使用辅助功能通过使用抗锯齿功能使椭圆看起来更平滑。但是,我认为此辅助功能中的蒙版引起了一个问题,即它在灰色背景的每个角上都留下了一个很小的(绿色)轮廓。
对于我的角落,我正在使用另一个帮助器函数来创建它们。也许这两个功能都有些冲突,但我不太确定。
这就是我想要做的:
def draw_ellipse(image, bounds, width=1, outline='white', antialias=4):
"""Improved ellipse drawing function, based on PIL.ImageDraw."""
# Use a single channel image (mode='L') as mask.
#The size of the mask can be increased relative to the imput image
# to get smoother looking results.
mask = Image.new(size=[int(dim * antialias) for dim in image.size], mode='L', color='black')
draw = ImageDraw.Draw(mask)
# draw outer shape in white (color) and inner shape in black (transparent)
for offset, fill in ( -7, 'white' ), ( width, 'black' ):
left, top = [(value + offset) * antialias for value in bounds[:2]]
right, bottom = [(value - offset) * antialias for value in bounds[2:]]
draw.ellipse([left, top, right, bottom], fill=fill)
# downsample the mask using PIL.Image.LANCZOS
# (a high-quality downsampling filter).
mask = mask.resize(image.size, Image.LANCZOS)
# paste outline color to input image through the mask
image.paste(outline, mask=mask
def add_corners(im, rad):
circle = Image.new('L', (rad * 2, rad * 2), 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
alpha = Image.new('L', im.size, 255)
w, h = im.size
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
alpha.paste(circle.crop((rad, rad, rad * 3, rad * 3)), (w - rad, h - rad))
im.putalpha(alpha)
return im
#Grey background
im = Image.new("RGBA", (900, 296), (44, 44, 44, 255))
#Add some corners
im = add_corners(im, 50)
im_draw = ImageDraw.Draw(im)
#Green Ellipse
ellipse_box = [55, 37, 107 + 48 + 46, 103 + 80]
draw_ellipse(im, ellipse_box, width=20, outline=(52, 235, 52))
im.save("image.png")
输出:
答案 0 :(得分:0)
int[] random_numbers = {10, 30, 44, 21, 51, 21, 61, 24, 14}
int array_length = random_numbers.Length;
for (int i = 0; i < array_length; i++){
if(i == array_length - 1){
Console.Write($"{random_numbers[i]}\n");
} else{
Console.Write($"{random_numbers[i]}, ");
}
}
这部分代码应放在
之后#SingleInstance force
#warn
SetTimer, HN, 2500
return
r::Reload
x::ExitApp
HN:
If WinActive("ahk_class Notepad")
WinSet, Style, -0xC00000, A
return
这可以解决问题。