如果您要绘制像这样的叠加层:
所以基本上你要做的就是在画布的帮助下将 customImage 强加在背景框上。使用此实现,您可以有效地从画布创建 BitmapDrawable,然后您可以将其指定为“ItemizedOverlay”的标记。如果这是您要查找的逐项叠加类型,则无需覆盖逐项叠加类的绘制函数。您需要做的就是使用以下代码创建一个 BitmapDrawable,您可以在其构造函数中将其分配给 ItemizedOverlay。这是执行此操作的函数:
public BitmapDrawable imageOnDrawable(int drawableBackground, Bitmap customImage)
{
//The following line is optional but I'd advise you to minimize the size of
//the size of the bitmap (using a thumbnail) in order to improve draw
//performance of the overlays (especially if you are creating a lot of overlays).
Bitmap customImageThumbnail = ThumbnailUtils.extractThumbnail(
customImage, 100, 100);
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId);
bm = Bitmap.createScaledBitmap(bm, 112, 120, false);
Canvas canvas = new Canvas(bm);
canvas.drawBitmap(bm, 0, 0, null);
// The 6,6 in the below line refer to the offset of the customImage/Thumbnail
// from the top-left corner of the background box (or whatever you want to use
// as your background)
canvas.drawBitmap(customImageThumbnail, 6, 6, null);
return new BitmapDrawable(bm);
}