i've create a Maps with any images using this code:
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);
but when i rotated the image, the result is very grainy (like the green arrow in this example: http://img837.imageshack.us/img837/4624/screenshot2013052111381.png)
i've wrong something? it's possibile bettering the definition?
It looks like you need to draw with anti-aliasing enabled. In this line:
canvas.drawBitmap(icon_pin, new Matrix(), null);
You can specify a Paint
object to use for drawing. Above, you use null
. You can add these lines before your call to canvas.drawBitmap()
:
Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
myPaint.setFilterBitmap(true);
Then change your last line to:
canvas.drawBitmap(icon_pin, new Matrix(), myPaint);
This code creates a new Paint
object with anti-aliasing enabled, which will hopefully take out the jagged edges on your markers.
Note: You can also use Paint
to apply colors, alpha shading and other cool effects to your drawing. See the Android documentation here.