我有个问题.我需要合并两个不同大小的图片(drawables).这个想法是让某人(动态加载)的图片为100x100px并且具有更大的透明背景(例如100×120).在最后20个像素中,我有一个箭头,应该指向一个人在地图上的位置.然后我想我可以这样做:
Drawable[] layers = new Drawable[2];
layers[0] = res.getDrawable(R.drawable.background_img);
layers[1] = res.getDrawable(R.drawable.icon);
LayerDrawable layerDrawable = new LayerDrawable(layers);
但这只是将一个图像叠加到另一个图像上而忽略了它们的边界.
提前致谢,
Vaidas
– 更新:最后解决了问题.奇迹般有效 :)
private Drawable createPersonDrawable(Bitmap personImage)
{
Bitmap resultingBitmap = Bitmap.createBitmap(drawableWidth,
drawableHeight, Bitmap.Config.ARGB_8888);
Canvas comboCanvas = new Canvas(resultingBitmap);
comboCanvas.drawBitmap(personImage, 0, 0, null);
// Get the bottom part of the image from resources
Bitmap bottomPart = BitmapFactory.decodeResource(getResources(),
R.drawable.person_map_icon_bottom);
comboCanvas.drawBitmap(bottomPart, 0, drawablePersonImageHeight, null);
comboCanvas.save();
return new BitmapDrawable(resultingBitmap);
}