2013-02-22 28 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