android - 在圆弧中心绘制位图?

标签 android android-canvas

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

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


编辑:插图草图:

enter image description here

最佳答案

This answer经过一些调整后对我有很大帮助:

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

关于android - 在圆弧中心绘制位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12273040/

相关文章:

Android Studio 找不到 OpenCV header

android - 在 Android 中使用 arcTo 创建凹路径

java - 如何在 android/java 中使用矩阵移动和旋转 Canvas 中的位图?

android - Canvas.getClipBounds 是否分配一个 Rect 对象?

Android:使 Firebase Auth 可用于所有 Activity

android - 使用 Android 进行移动应用程序开发

Android Studio Git .gitignore 与项目 > 设置 > 版本控制 > 忽略文件

android - 具有透明背景的 BottomAppBar 内的 BottomNavigationView

android - 为什么我的卡片 View 没有被绘制到 Canvas 上?

android - 绘图 Canvas FC