Issue
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);
}
Whenever I call this the marker dissapears instead of rotating. What am I doing wrong?
Solution
Instead of going through the hassle of creating a new Canvas and all that use Bitmap.createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter). When you create your rotation matrix, use half the width and height passed to the createBitmap function. After this create your BitmapDrawable.
Answered By - Dan S
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.