2013-02-22 33 views
1

我想2個圖像合併,所以我搜查,看到了一個代碼在這裏snipplet combining two png files in androidBitmapFactory.decodeFile不能在一類解決

Bitmap bottomImage = new BitmapFactory.decodeFile("myFirstPNG.png"); 
Bitmap topImage = new BitmapFactor.decodeFile("myOtherPNG.png"); 


Canvas comboImage = new Canvas(bottomImage); 
// Then draw the second on top of that 
comboImage.drawBitmap(topImage, 0f, 0f, null); 

// bottomImage is now a composite of the two. 

// To write the file out to the SDCard: 
OutputStream os = null; 
try { 
    os = new FileOutputStream("/sdcard/DCIM/Camera/" + "myNewFileName.png"); 
    image.compress(CompressFormat.PNG, 50, os) 
} catch(IOException e) { 
    e.printStackTrace(); 
} 

我試圖使用它,但出於某種原因位圖底圖=新的BitmapFactory.decodeFile(「myFirstPNG.png」);是給錯誤BitmapFactory不能resovlved成類型,但我已經有兩個

import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 

我使用PhoneGap的,我把這個在主要活動,以測試

+0

刪除位圖中的「新」bottomImage = new BitmapFactory.decodeFile(「myFirstPNG.png」); 位圖topImage = new BitmapFactor.decodeFile(「myOtherPNG.png」); – Pragnani 2013-02-22 05:50:55

回答

4

decodeFile是需要一個靜態方法在類範圍內被稱爲如下:

Bitmap bottomImage = BitmapFactory.decodeFile("myFirstPNG.png"); 
Bitmap topImage = BitmapFactor.decodeFile("myOtherPNG.png"); 

(注意到new關鍵字已被刪除)

+0

哦,所以新的應該在那裏? – jhdj 2013-02-22 05:28:36

+0

修復了這個問題,但是當我運行時,我在這一行中得到一個空指針錯誤** Canvas comboImage = new Canvas(bottomImage); **和im確定我把圖像放在同一個目錄下測試仍然出錯 – jhdj 2013-02-22 06:41:07