在谷歌地图中旋转的粒状标记

时间:2013-05-21 10:00:16

标签: android google-maps canvas rotation markers

我使用此代码创建了包含任何图片的地图:

icon_pin = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.arrow);
int w = icon_pin.getWidth();
int h = icon_pin.getHeight();
Bitmap.Config conf = Bitmap.Config.ARGB_8888;

Bitmap bmp = Bitmap.createBitmap(w, h, conf); 


final float centerX = w / 2.0f;
final float centerY = h / 2.0f;

Canvas canvas = new Canvas(bmp);
canvas.rotate(m.getDirection(), centerX, centerY);

canvas.drawBitmap(icon_pin, new Matrix(), null);

但是当我旋转图像时,结果非常颗粒状(如本例中的绿色箭头:http://img837.imageshack.us/img837/4624/screenshot2013052111381.png

我错了什么? 它有可能改善定义吗?

1 个答案:

答案 0 :(得分:1)

看起来你需要在启用消除锯齿的情况下进行绘制。在这一行:

canvas.drawBitmap(icon_pin, new Matrix(), null);

您可以指定用于绘图的Paint对象。在上方,您使用null。您可以在调用canvas.drawBitmap()之前添加以下行

Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
myPaint.setFilterBitmap(true);

然后将您的最后一行更改为:

canvas.drawBitmap(icon_pin, new Matrix(), myPaint);

此代码会创建一个新的Paint对象,并启用了抗锯齿功能,有望取出标记上的锯齿状边缘。

注意:您还可以使用Paint将颜色,Alpha着色和其他炫酷效果应用于绘图。请参阅Android文档here