我想在android中的單擊方法上繪製標記。當我畫出標記時,它會畫出來,但是畫出30-40毫秒需要更多的時間,有時需要2-3秒。這裏是我的繪圖方法的類的代碼。如何在canvas中的onDraw()方法中快速繪製位圖android
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
public MyItemizedOverlay(Drawable pDefaultMarker,
ResourceProxy pResourceProxy) {
super(pDefaultMarker, pResourceProxy);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean arg2) {
super.draw(canvas, mapView, arg2);
// ---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
// ---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_darkblue);
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_green);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_bue);
Bitmap bmp3 = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_light);
Bitmap bmp4 = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_light);
Bitmap bmp5 = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_light);
Bitmap bmp6 = BitmapFactory.decodeResource(getResources(),
R.drawable.pin_annotation_light);
if (count == 1) {
int caller = getIntent().getIntExtra("button", 0);
switch (caller) {
case R.id.btMap:
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
bmp.recycle();
break;
case R.id.imageButton1:
canvas.drawBitmap(bmp1, screenPts.x, screenPts.y - 50, null);
bmp1.recycle();
break;
case R.id.imageButton2:
canvas.drawBitmap(bmp2, screenPts.x, screenPts.y - 50, null);
bmp2.recycle();
break;
case R.id.imageButton3:
canvas.drawBitmap(bmp3, screenPts.x, screenPts.y - 50, null);
bmp3.recycle();
break;
case R.id.imageButton4:
canvas.drawBitmap(bmp4, screenPts.x, screenPts.y - 50, null);
bmp4.recycle();
break;
case R.id.imageButton5:
canvas.drawBitmap(bmp5, screenPts.x, screenPts.y - 50, null);
bmp5.recycle();
break;
case R.id.imageButton6:
canvas.drawBitmap(bmp6, screenPts.x, screenPts.y - 50, null);
bmp6.recycle();
break;
}
}
// Bitmap bmp = BitmapFactory.decodeResource(getResources(),
// R.drawable.pin_annotation_green);
// if (count == 1) {
// canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
// }
}
讓我們[在聊天中繼續討論](http://chat.stackoverflow.com/rooms/40102/discussion-between-gaurav-kumar-and-yushulx) –
感謝您分享代碼。但我不認爲你需要第一個例子中的開關。只要這樣做:'int caller = getIntent()。getIntExtra(「button」,0); Bitmap bmp = mStore.get(caller); canvas.drawBitmap(bmp,screenPts.x,screenPts.y - 50,null); bmp.recycle(); bmp = null; 休息; }' –