I have a problem. I need to combine two images of different sizes (drawables). The idea is to portray someone (dynamically loaded) with a size of 100x100 pixels and have a transparent background that is larger (e.g. 100x120). In these last 20 pixels, I have an arrow that should indicate the location of the person on the map. Then I think I can do something like this:
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);
But it just overlays one image on another, ignoring their boundaries.
Thanks in advance, Vaidas
- UPDATE: finally solved the problem. It works like a charm :)
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);
Bitmap bottomPart = BitmapFactory.decodeResource(getResources(),
R.drawable.person_map_icon_bottom);
comboCanvas.drawBitmap(bottomPart, 0, drawablePersonImageHeight, null);
comboCanvas.save();
return new BitmapDrawable(resultingBitmap);
}
I found a description here: http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas
source