我已经设置了这个窗口,在这个窗口中,我在屏幕上画一个椭圆.我希望椭圆形是全白的,边框光滑.它看起来可以接受,但当我将椭圆添加到白色背景时,椭圆的边框就会显示出来.
import pygame
import cv2
import numpy as np
pygame.init()
# Set up the Pygame window
screen_width = 640
screen_height = 480
screen = pygame.display.set_mode((screen_width, screen_height))
def drawAACircle(surf, color, center, radius, width, angle):
circle_image = np.zeros((radius*2, radius*2, 4), dtype = np.uint8)
circle_image = cv2.ellipse(circle_image, (radius, radius), (radius-width, radius-width), (angle*-.5)-90 , 0, angle, (*color, 255), width, lineType=cv2.LINE_AA)
#draw it on the surface
surf.blit(pygame.image.frombuffer(circle_image.tobytes(), circle_image.shape[1::-1], "RGBA").convert_alpha(), (center[0]-radius, center[1]-radius))
# Wait for the user to close the window
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.fill((255,255,255))
drawAACircle(screen, (255,255,255), (screen_width/2,screen_height/2), 200, 20, 360)
# Update the display
pygame.display.flip()
当我将背景更改为全白时,我注意到了边框:
我目前正在开发一个贴花工具,可以将多个椭圆堆叠在一起.我用copy()
刷新背景屏幕,如下所示:
def takeSnapshot():
global snapshot
snapshot = screen.copy()
def clearSnapshot():
global snapshot
snapshot = None
----
# Run the main loop
running = True
while running:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
# Clear the screen
if snapshot is None:
screen.fill((0,0,0))
else:
screen.blit(snapshot, (0,0))
我已经使用填充的多边形try 了gfx.aapolygon ICM.但我就是不能把它弄得像OpenCV椭圆一样干净利落.
如果有人知道另一种 Select ,我会很高兴听到的,或者我可能忽略了一些我可以只得到完全白色的OpenCV椭圆的地方.
编辑:为了清楚起见,我 Select 了OpenCV椭圆作为厚度选项,可以做出一个弧形,看起来很流畅.