1

私は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を使用しており、これをメインアクティビティに入れてテストします

4

1 に答える 1

4

decodeFileは、次のようにクラス スコープで呼び出す必要がある静的メソッドです。

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

new(キーワードが削除されていることに注意してください)

于 2013-02-22T05:20:15.400 に答える