2011-03-31 95 views
8

因此,我有兩個圖像本地存儲在SD卡上的android和我想結合成一個圖像。它很難解釋,所以我將鏈接到一張圖片,以便更好地展示我想如何拍攝前兩張圖片並將它們合併到最後。在Android中結合兩個圖像java

http://img850.imageshack.us/i/combinedh.jpg/

+0

http://kyogs.blogspot.in/2012/08/mearge-images.html ..引用這一個 – kyogs 2012-10-23 13:52:06

回答

9

創建目標Bitmap,爲它創建一個Canvas,使用Canvas.drawBitmap每個源位位塊傳輸到你的目標位。

2

最簡單的方法可能是在RelativeLayout中使用兩個ImageView。您可以在佈局中將ImageView放置在彼此的頂部。

9

一般我用下面的函數from Jon Simon組合兩個位圖作爲參數傳遞和獲取相結合的位圖作爲輸出,

public Bitmap combineImages(Bitmap c, Bitmap s) 
{ 
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) { 
     width = c.getWidth() + s.getWidth(); 
     height = c.getHeight(); 
    } else { 
     width = s.getWidth() + s.getWidth(); 
     height = c.getHeight(); 
    } 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 

    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, c.getWidth(), 0f, null); 

    return cs; 
}