2013-02-02 113 views
0

我試圖合併2個圖像,一個是來自相機的位圖,第二個是.png文件存儲在繪圖中。我所做的是我用了兩個圖像爲位圖,我嘗試用帆布,這樣的合併它們:從相機合併圖像與繪圖的圖像

Bitmap topImage = BitmapFactory.decodeFile("gui.png"); 
Bitmap bottomImage = BitmapFactory.decodeByteArray(arg0, 0, arg0.length); 

Canvas canvas = new Canvas(bottomImage); 
canvas.drawBitmap(topImage, 0, 0, null); 

但我不斷收到「位圖大小超過VM預算」的錯誤所有的時間。我嘗試了幾乎所有的東西,但仍然會一直拋出這個錯誤。還有另一種合併2個圖像的方式嗎?我需要做的事情很簡單 - 我需要拍照並將其與保存在繪圖中的.PNG圖像合併。例如,這個應用程序非常接近我需要的 - https://play.google.com/store/apps/details?id=com.hl2.hud&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5obDIuaHVkIl0

謝謝:)

回答

3

請參閱下面的代碼來合併兩個圖像。 此方法返回結合位

public Bitmap combineImages(Bitmap frame, Bitmap image) { 
     Bitmap cs = null; 
     Bitmap rs = null; 

     rs = Bitmap.createScaledBitmap(frame, image.getWidth() + 50, 
       image.getHeight() + 50, true); 

     cs = Bitmap.createBitmap(rs.getWidth(), rs.getHeight(), 
       Bitmap.Config.RGB_565); 

     Canvas comboImage = new Canvas(cs); 

     comboImage.drawBitmap(image, 25, 25, null); 
     comboImage.drawBitmap(rs, 0, 0, null); 
     if (rs != null) { 
      rs.recycle(); 
      rs = null; 
     } 
     Runtime.getRuntime().gc(); 
     return cs; 
    } 

你可以改變高度和寬度按您的要求 希望這將有助於...

0

圖像有多大?在嘗試將大圖像加載到內存時,我只遇到了這個問題。

字節數組實際上是解碼圖像嗎?

從快速瀏覽android文檔,您可以使用默認的相機應用程序捕獲圖像,這可能在這種情況下工作。

http://developer.android.com/training/camera/photobasics.html

也看到了這個問題:Capture Image from Camera and Display in Activity

編輯:您可能還需要縮放來自攝像頭的圖像下來,如果它是非常大的。查看我鏈接到的Android頁面的結尾,以獲取有關詳情。

+0

好吧,我用這個代碼示例,我的目的 - HTTP://機器人-er.blogspot.sk/2011/01/start-camera-auto-focusing-autofocus.html 它正是我所需要的 - 從相機預覽圖像,在buttonclick上拍照,在屏幕上點擊自動對焦。 問題在於合併來自此代碼的照片與存儲在繪圖中的.PNG圖像。 – andrejbroncek