1

私は2つの画像を持っています。1つの画像には顔のない体が含まれており、1つの画像には顔のみが含まれています...

今、私はこの2つの画像をマージしたい....顔のない体だけを含む最初の画像は、顔が透明であることです.....

では、その透明な領域を検出し、その透明な領域に顔を配置するにはどうすればよいですか?

以下のコードで 2 つの画像を結合していますが、透明な領域に顔を配置するのは適切な方法ではありません

私のコードは以下のとおりです。

public Bitmap combineImages(Bitmap c, Bitmap s) {
    Bitmap cs = null;

    int width, height = 0;

    if (c.getWidth() > s.getWidth()) {
        width = c.getWidth() + s.getWidth();
        height = c.getHeight();
    } else {
        width = s.getWidth() + s.getWidth();
        height = c.getHeight();
    }

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas comboImage = new Canvas(cs);

    comboImage.drawBitmap(c, 0f, 0f, null);
    comboImage.drawBitmap(s, 0f, 0f, null);

    return cs;
}
4

2 に答える 2

1

以下のコードを使用して簡単に画像をマージできる Canvas を使用して、Android で 2 つ以上の画像をマージします。最初に、マージする特定の画像のビットマップを作成します。

画像をマージする領域の X 軸と Y 軸の位置を取得します。

    mComboImage = new Canvas(mBackground);

   mComboImage.drawBitmap(c, x-axis position in f, y-axis position in f, null);

    mComboImage.drawBitmap(c, 0f, 0f, null);
    mComboImage.drawBitmap(s, 200f, 200f, null);


    mBitmapDrawable = new BitmapDrawable(mBackground);
    Bitmap mNewSaving = ((BitmapDrawable)mBitmapDrawable).getBitmap();

この新しいビットマップをイメージビューに設定します。imageView.setImageBitmap(mNewSaving);

このメソッドでは、2 つの画像ビットマップが 1 つのビットマップに結合され、新しいマージ画像のビットマップが返されます。また、この画像を sdcard に保存します。以下のコードのように

public Bitmap combineImages(Bitmap c, Bitmap s) {
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) { 
      width = c.getWidth(); 
      height = c.getHeight() + s.getHeight(); 
    } else { 
      width = s.getWidth(); 
      height = c.getHeight() + s.getHeight(); 
    } 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 
    comboImage.drawBitmap(c, new Matrix(), null);
    comboImage.drawBitmap(s, new Matrix(), null);

    // this is an extra bit I added, just incase you want to save the new image somewhere and then return the location.

    return cs; 
  } 
}
于 2013-04-23T05:36:50.063 に答える
0

2 つのビットマップをマージする適切な方法は次のとおりです。

    public Bitmap combineImages(Bitmap topImage, Bitmap bottomImage) {
        Bitmap overlay = Bitmap.createBitmap(bottomImage.getWidth(), bottomImage.getHeight(), bottomImage.getConfig());
        Canvas canvas = new Canvas(overlay);
        canvas.drawBitmap(bottomImage, new Matrix(), null);
        canvas.drawBitmap(topImage, 0, 0, null);
        return overlay;
    }
于 2016-04-25T04:59:25.617 に答える