创建椭圆/圆矩形内 [英] Creating oval/circle inside a rectangle
本文介绍了创建椭圆/圆矩形内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个矩形内椭圆/圆。我试图做到这一点在画布上的位图图像。这里是我的code:
I am trying to create an oval/circle inside a rectangle. I am trying to do this on canvas for a bitmap image. Here is my code:
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);
现在我想创建这个矩形内的一个椭圆/圆。我尝试这样做,一直在努力了几个小时不能得到它的工作:
Now i want to create an oval/circle inside this rectangle. I tried this and been trying for hours cant get it to work:
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);
有人可以帮我想出解决办法?
下面是可视化,以帮助我试图来实现:
Can someone please help me figure this out? Here is visual to help what i am trying to achieve:
推荐答案
您应该使用相同的范围比你用于绘制矩形:
You should use the same bounds than you used for drawing the rectangle:
RectF rect = new RectF(left, top, right, bottom);
canvas.drawRect(rect, paint);
canvas.drawOval(rect, paint);
这篇关于创建椭圆/圆矩形内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文