我遇到問題。我需要合併兩個不同大小的圖片(可繪製)。這個想法是讓一張100x100像素(動態加載)的圖片具有較大的透明背景(例如100x120)。在最後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);
}
我發現這裏的描述:http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas
感謝。我會嘗試發佈結果。 – 2012-01-05 18:59:44