我正在努力将一个圆形绘制在一个矩形png背景上。每当我尝试绘制一个圆时,它会根据我的图像比例进行拉伸--使其成为椭圆而不是圆。
这是我的设置:
#set background image
surface = cairo.ImageSurface.create_from_png (image)
context = cairo.Context (surface)
WIDTH = cairo.ImageSurface.get_width(surface)
HEIGHT = cairo.ImageSurface.get_height(surface)
context.scale (WIDTH, HEIGHT)
这里是绘制圆形的函数,(x坐标, y坐标, 半径, 颜色值),还有用于定位的函数:
def draw_node(cx,cy,r, rgb):
context.arc(x_scale(cx), y_scale(cy), r, 0, 2 * math.pi)
context.set_source_rgb(rgb[0]/255.0,rgb[1]/255.0,rgb[2]/255.0)
context.fill()
context.stroke()
def x_scale (x):
width = 1000.0
return (x + .5) / width
def y_scale (y):
height = 1000.0 * HEIGHT / WIDTH
return (y + .5) / height
我希望您能就系统缩放问题提供解决建议,同时也希望您能就如何在现有设置的限制下画圆提供建议。非常感谢。