2013-11-23 77 views
0

我正尝试在矩形内创建一个椭圆/圆形。我正在试图在画布上做一个位图图像。这里是我的代码:在矩形内创建椭圆/圆形

int x = (int) (midpoint.x*xRatio); 
int y = (int) (midpoint.y*yRatio); 
int radius = (int) (distance/2); 
int left = x - radius; 
int right = x + radius; 
int top = y - radius; 

canvas.drawRect(left, top, right, bottom, paint); 

现在我想要创建一个椭圆/这个矩形内的圆。我试了这个,一直试图数小时不能得到它的工作:

RectF ovalBounds = new RectF(); 
//ovalBounds.set(x, y, (right - left)/2, (bottom-top)/2); 
ovalBounds.set(x, y-radius, radius * 2, radius * 2); 
canvas.drawOval(ovalBounds, paint);     

有人可以帮我解决这个问题吗? 这里是视觉帮助我试图实现: enter image description here

+0

@HovercraftFullOfEels - 我这样做对日食的一种android应用程序。 – NoviceMe

+0

@HovercraftFullOfEels - 对不起会添加它们.. – NoviceMe

+0

你的canvas.drawOval-call在哪里? – isnot2bad

回答

3

你应该比你用于绘制矩形使用相同的边界:

RectF rect = new RectF(left, top, right, bottom); 
canvas.drawRect(rect, paint); 
canvas.drawOval(rect, paint);