我正在使用imageview
创建Android应用程序以绘制地图。
我使用自定义touchImageView
类来查看地图并能够缩放和移动。
现在我想在该地图上绘制并旋转它:
我正在尝试这样做,但箭头图像正在移动,如下所示:
这段代码我习惯这样做:
@Override
protected void onDraw(Canvas canvas) {
// This code to drawing the image
super.onDraw(canvas);
Paint paint = new Paint();
matrix.reset();
matrix.postTranslate(-width / 2.0f, -height / 2.0f);
matrix.postRotate(0);
matrix.postScale(scale, scale);
matrix.postTranslate(position.getX(), position.getY());
canvas.drawBitmap(bitmap, matrix, paint);
canvas.concat(matrix);
// This code to drawing the arrow image and rotate it
Bitmap ArrowSource = BitmapFactory.decodeResource(this.getResources(), R.drawable.arrow);
Matrix ArrowMatrix = new Matrix();
ArrowMatrix.postRotate(-Globals.theta);
Bitmap DrawingBitmap=Bitmap.createBitmap(ArrowSource, 0, 0, 125, 125, ArrowMatrix, false);
canvas.drawBitmap(DrawingBitmap, 125, 125, null);
}