我正在尝试合并2张图片,所以我搜索并在此处看到了代码片段combining two png files in android
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();
}
我尝试使用它,但出于某种原因 Bitmap bottomImage = new BitmapFactory.decodeFile(“myFirstPNG.png”); 给出一个错误,即BitmapFactory无法重新转换为类型但我已经拥有两个
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
我正在使用phonegap,我把它放在主要活动中进行测试
答案 0 :(得分:4)
decodeFile
是一个静态方法,需要在类范围内调用,如下所示:
Bitmap bottomImage = BitmapFactory.decodeFile("myFirstPNG.png");
Bitmap topImage = BitmapFactor.decodeFile("myOtherPNG.png");
(请注意new
关键字已被删除)