私は2つの画像を結合しようとしているので、Androidで2つのpngファイルを結合するコードスニペットを検索して見ました
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を使用しており、これをメインアクティビティに入れてテストします