核心代码:

 

int  index=20;

Drawable icon = HistoryItemizedOverlay.mSelectedIcon;
            int w = icon.getIntrinsicWidth();
            int h = icon.getIntrinsicHeight();
            Log.e(TAG, "打印的宽高=" + w + "," + h);
            Bitmap newBitmap = Bitmap.createBitmap(w, h,
                    Bitmap.Config.ARGB_8888);

            Canvas c = new Canvas(newBitmap);
            Paint paint = new Paint();
            paint.setColor(Color.RED);
            paint.setTextSize(15);
            paint.setFakeBoldText(true);
            float strWidth = paint.measureText(String.valueOf(index)); //计算文字的字宽

            // 要在这个图上画文字
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.pin_red);
            c.drawBitmap(bitmap, 0, 0, null);
            c.drawText(String.valueOf(index), (w-strWidth)/2, 15, paint);
            c.save(Canvas.ALL_SAVE_FLAG);// 保存
            c.restore();// 存储

            BitmapDrawable bd = new BitmapDrawable(newBitmap);