我对Android很新,并且一直在玩Canvas.我试图画一个箭头,但我只是在绘制轴时没有运气,箭头都没有工作.
我搜索了一下,发现了一个Java示例,但Android没有GeneralPath或者AffineTransform.
现在我的代码如下所示(箭头看起来像箭头):
public class DrawableView extends View {
Context mContext;
private int centerX;
private int centerY;
private int radius;
private double arrLength;
private double arrHeading;
private int margin = 10;
public DrawableView(Context context) {
super(context);
mContext = context;
}
@Override
protected void onDraw(Canvas canvas) {
//Paint Background
Paint background = new Paint();
background.setColor(getResources().getColor(R.color.background);
canvas.drawRect(0, 0, getWidth(), getHeight(), background);
//Set vars for Arrow Paint
Paint paint = new Paint();
paint.setColor(getResources().getColor(R.color.arrowColor);
centerX = getWidth() / 2;
centerY …Run Code Online (Sandbox Code Playgroud) 我正在努力在其中心周围绘制一个旋转位图,并在不调整位图大小的情况下进行旋转.我正在通过游戏线程将所有精灵绘制到屏幕上,所以我正在寻找一种包含原始位图而不是画布的解决方案.
提前致谢.
到目前为止,这是我的代码,它围绕其中心转换位图,然后调整它的大小.
i = i + 2;
transform.postRotate(i, Assets.scoresScreen_LevelStar.getWidth()/2, Assets.scoresScreen_LevelStar.getHeight()/2);
Bitmap resizedBitmap = Bitmap.createBitmap(Assets.scoresScreen_LevelStar, 0, 0, Assets.scoresScreen_LevelStar.getWidth(), Assets.scoresScreen_LevelStar.getHeight(), transform, true);
game.getGraphics().getCanvasGameScreen().drawBitmap(resizedBitmap, null, this.levelStar.getHolderPolygons().get(0), null);
Run Code Online (Sandbox Code Playgroud)
更新:
我注意到这并不像听起来那么容易.我的旋转代码不是问题.位图旋转,但是dst rect也必须根据旋转角度增加/减少,否则bimap会显得更小,因为它被绘制到固定的dst rect中.所以我猜我必须开发一些会返回dst rect的方法. 所以旋转位图所需的方法没有出现调整大小:
public static Bitmap rotateBitmap(Bitmap bitmap, int rotation) // I've got this method working
Run Code Online (Sandbox Code Playgroud)
和
public static Rect rotateRect(Rect currentDst, int rotation) // Don't got this
Run Code Online (Sandbox Code Playgroud)
我明白这需要一些数学(触发),任何人都可以接受挑战吗?:P