【问题标题】:Draw a Bitmap in Arc center?在弧中心绘制位图?
【发布时间】:2012-09-05 00:29:23
【问题描述】:

在我的自定义视图中,我绘制了多个填充的Arcs,如下所示:

canvas.drawArc(oval, startAngle, sweepAngle, true, sectorPaint);

现在,我想在圆弧的中心绘制一个图标。我从这个开始:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_icon);
canvas.drawBitmap(bitmap, pointX, pointY, null); //pointX & pointY ??

但是,我不知道应该为pointXpointY 设置什么。这是我的数据:

  • 椭圆中心坐标和半径。
  • startAngle 和 sweepAngle(因此可以导出 endAngle)

有没有办法知道pointXpointY 给出这些输入的值?


编辑:插图草图:

【问题讨论】:

  • 你能把你想要实现的屏幕截图也放上来
  • @SunnyKumarAditya 用草图编辑。请看一下。

标签: android android-canvas


【解决方案1】:

This answer经过一些调整帮助了我很多:

double radius = width/2;
double x = radius + (radius)*Math.cos(-angle);
double y = radius + (radius)*Math.sin(-angle);

【讨论】:

  • 我认为这只有在你的起始角度为 0 时才有效。有没有办法设置一个非零的起始和结束角度并且仍然得到它们的中心?
【解决方案2】:

使用你的变量。

试试这个:

double x = C.x + r * Math.cos(theta * Math.PI / 180);
double y = C.y + r * Math.sin(theta * Math.PI / 180);

其中thetaarc - start angle of arc 的结束角

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多