2012-01-05 75 views
5

我遇到問題。我需要合併兩個不同大小的圖片(可繪製)。這個想法是讓一張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

回答

1

我沒有確切的命令,在這裏,但你應該做的:

  1. 同生共創建位圖你想要的大小。
  2. 創建一個帆布經過創建位圖
  3. 畫在畫布上的兩個圖像。
  4. 位圖添加到您正在使用的視圖。
+0

感謝。我會嘗試發佈結果。 – 2012-01-05 18:59:44

1

如果要更改LayerDrawable中的可繪製大小和位置,可以使用setLayerSize更改可繪製大小,並且可以使用setLayerInset來控制位置。