0

我正在使用函數來將兩個位圖文件彼此對齊並且它也覆蓋。 我正在使用此函數將它覆蓋在一個另一個上。覆蓋位圖功能無法正常工作

public static Bitmap combineImages(Bitmap cameraImage, Bitmap visionImage) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom 

    Bitmap finalImage = null; 
     int width, height = 0; 
      width = cameraImage.getWidth(); 
      height = cameraImage.getHeight(); 

     finalImage = Bitmap.createBitmap(width, height, cameraImage.getConfig()); 

     Canvas canvas = new Canvas(finalImage); 

     canvas.drawBitmap(cameraImage, new Matrix(), null); 
     canvas.drawBitmap(visionImage, new Matrix(), null); 

     // this is an extra bit I added, just incase you want to save the new image somewhere and then return the location 
     /*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png"; 

     OutputStream os = null; 
     try { 
      os = new FileOutputStream(loc + tmpImg); 
      finalImage.compress(CompressFormat.PNG, 100, os); 
     } catch(IOException e) { 
      Log.e("combineImages", "problem combining images", e); 
     }*/ 

     return finalImage; 
     } 

但保存完這個圖像後,我顯示圖像要相互結合。它不是覆蓋。我希望它可以疊加在一起。

請告訴我我在哪裏錯了這個函數? 謝謝。

+0

你想結合位圖的像一個覆蓋另一個。 –

+0

我的第一張圖片是cameraPicture和TransperentLayer的第二張圖片。所以我想把第二張傳送圖像疊加到FirstOne圖像上。 –

+0

看到我的答案,它會做.. –

回答

1

這是將兩張位圖的功能,S

private Bitmap overlayMark(Bitmap bmp1, Bitmap bmp2) { 
    int bh = originalBitmap.getHeight(); 
    int bw = originalBitmap.getWidth(); 
    Bitmap bmOverlay = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888); 
    Canvas canvas = new Canvas(bmOverlay); 
    canvas.drawBitmap(bmp1, 0, 0, null); 
    canvas.drawBitmap(bmp2, 0,0, null); 
    return bmOverlay; 
} 
+0

我已經使用你的功能但結果是一樣的,像以前一樣。我想讓這兩個圖像疊加在一起。但是保存的圖像看起來像是相互結合在一個圖像文件中單獨顯示的。 –

+0

你的答案不適合我。我得到了同樣的結果,因爲我之前得到 –

+0

你可以發佈屏幕截圖的東西嗎? –