【问题标题】:Grainy Markers with rotation in GoogleMaps谷歌地图中带有旋转的粒状标记
【发布时间】:2013-05-16 01:21:41
【问题描述】:

我已经使用此代码创建了一个包含任何图像的地图:

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

我做错了什么? 是否可以更好地定义?

【问题讨论】:

  • 很可能是关于别名的。

标签: android google-maps canvas rotation markers


【解决方案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

【讨论】:

    猜你喜欢
    • 2012-05-20
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多