2016-01-11 325 views
0

我知道這個問題已經回答了,但是沒有幫到我。我的問題是不要重疊圖像,我想要加入兩個單獨的圖像,它們的大小相同,如下所示。將兩張圖片合併成一張圖片

[我要像下圖] [1]

下面是代碼:用於圖片

private Bitmap createSingleImageFromMultipleImages(Bitmap firstImage, Bitmap secondImage) { 

     Bitmap result = Bitmap.createBitmap(firstImage.getWidth(), firstImage.getHeight(), firstImage.getConfig()); 
     Canvas canvas = new Canvas(result); 
     canvas.drawBitmap(firstImage, 0f, 0f, null); 
     canvas.drawBitmap(secondImage, 200, 200, null); 
     return result; 
    } 

Bitmap mergedImages = createSingleImageFromMultipleImages(firstImage, SecondImage); 

        im.setImageBitmap(mergedImages); 

我越來越ovelapping形象結合起來。任何人都可以幫忙

謝謝。

+0

也許發佈您的代碼... –

+2

HTTP:/ /stackoverflow.com/questions/8415777/how-to-use-canvas-for-merging-two-images-in-android –

+1

@Marcin Orlowski我不想重疊圖像。請正確看到圖像,並建議請 – KCN

回答

0

如果要創建並排合併圖像,您需要創建一個結果位圖,其寬度爲第一個圖像的2倍,或者更可縮放地爲圖像的寬度總和:

當前,您正在創建寬度爲firstImage.getWidth()的結果圖像。它們將明顯重疊或不在畫布上。

此外,您還需要將第二圖像放置在X == firstImage.getWidth()

看看這個代碼(未經測試):

private Bitmap createSingleImageFromMultipleImages(Bitmap firstImage, Bitmap secondImage) { 
     Bitmap result = Bitmap.createBitmap(firstImage.getWidth() + secondImage.getWidth(), firstImage.getHeight(), firstImage.getConfig()); 
     Canvas canvas = new Canvas(result); 
     canvas.drawBitmap(firstImage, 0f, 0f, null); 
     canvas.drawBitmap(secondImage, firstImage.getWidth(), 0f, null); 
     return result; 
} 

Bitmap mergedImages = createSingleImageFromMultipleImages(firstImage, secondImage); 

im.setImageBitmap(mergedImages);