Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在矩形内创建椭圆形/圆形_Java_Android_Eclipse_Android Canvas - Fatal编程技术网

Java 在矩形内创建椭圆形/圆形

Java 在矩形内创建椭圆形/圆形,java,android,eclipse,android-canvas,Java,Android,Eclipse,Android Canvas,我试图在矩形内创建一个椭圆形/圆形。我尝试在画布上为位图图像执行此操作。这是我的密码: 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

我试图在矩形内创建一个椭圆形/圆形。我尝试在画布上为位图图像执行此操作。这是我的密码:

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);                 
有人能帮我弄清楚吗? 以下是帮助我实现目标的视觉效果:

您应该使用与绘制矩形相同的边界:

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

应使用与绘制矩形相同的边界:

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

应使用与绘制矩形相同的边界:

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

应使用与绘制矩形相同的边界:

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

@HoverCraftFullOfels-我正在eclipse上为android应用程序执行此操作。@HoverCraftFullOfels-抱歉将添加它们。.画布在哪里。drawOval调用?@isnot2bad-将其添加到上面。只是没有将代码粘贴到这里。@HovercraftFullOfEels-我正在eclipse上为android应用程序执行此操作。@HovercraftFullOfEels-抱歉将添加它们。.画布在哪里?drawOval调用?@isnot2bad-将其添加到上面。只是没有将代码粘贴到这里。@HovercraftFullOfEels-我正在eclipse上为android应用程序执行此操作。@HovercraftFullOfEels-抱歉将添加它们。.画布在哪里?drawOval调用?@isnot2bad-将其添加到上面。只是没有将代码粘贴到这里。@HovercraftFullOfEels-我正在eclipse上为android应用程序执行此操作。@HovercraftFullOfEels-抱歉将添加它们。.画布在哪里?drawOval调用?@isnot2bad-将其添加到上面。只是没有在这里粘贴代码。