椭圆与圆

时间:2011-02-16 13:36:12

标签: java gwt canvas



        Canvas canvas = Canvas.createIfSupported();

        canvas.setWidth("200px");
        canvas.setHeight("200px");

        RootPanel.get().add(canvas);

        Context2d context = canvas.getContext2d();
        context.setStrokeStyle("black");

        context.arc(50, 50, 20, 0, Math.PI*2);

        context.stroke();

为什么我在这里有椭圆而不是圆圈?

1 个答案:

答案 0 :(得分:4)

您还必须设置坐标空间,使其与画布的宽高比相匹配。所以你可以添加以下几行:

canvas.setCoordinateSpaceWidth(200);
canvas.setCoordinateSpaceHeight(200);