MapView中的标记在旋转后消失

时间:2011-07-19 17:52:17

标签: android android-mapview google-maps-markers

public Drawable rotateDrawable(int angle)
{
    Bitmap arrowBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.arrowscalled);

    // Create blank bitmap of equal size
    Bitmap canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_8888, true);
    canvasBitmap.eraseColor(0x00000000);

   // Create canvas
   Canvas canvas = new Canvas(canvasBitmap);

   // Create rotation matrix
   Matrix rotateMatrix = new Matrix();
   rotateMatrix.setRotate(angle, canvas.getWidth()/2, canvas.getHeight()/2);

   // Draw bitmap onto canvas using matrix
   canvas.drawBitmap(arrowBitmap, rotateMatrix, null);

   return new BitmapDrawable(canvasBitmap);
}

每当我打电话给它时,标记消失而不是旋转。我做错了什么?

1 个答案:

答案 0 :(得分:0)

而不是经历创建新Canvas和使用Bitmap.createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)的所有麻烦的麻烦。创建旋转矩阵时,请使用传递给createBitmap函数的宽度和高度的一半。在此之后创建您的BitmapDrawable。