MapView 中的标记在旋转后消失
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);
}
每当我调用此标记时,标记就会消失而不是旋转。我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是经历创建新画布和所有使用 Bitmap.createBitmap(位图源, int x、int y、int 宽度、int 高度、矩阵 m、布尔过滤器)。创建旋转矩阵时,使用传递给 createBitmap 函数的宽度和高度的一半。之后创建您的 BitmapDrawable。
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.