2013-04-23 79 views
1

我有一個的兩個圖像的一個圖像由包含身體無面和一個圖像包含僅臉...合併兩個圖像(一幅圖像是無面透明的,第二圖像是從SD卡來唯一面)

現在我想合併這兩個圖像....只包含身體沒有臉在面對的是透明的第一圖像.....

那麼,如何可以檢測透明區域和地方的臉在那裏在透明區域?

我結合了下面的代碼兩幅圖像..但不要把臉上掠過透明區域下方

我的代碼被賦予適當的方式,

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; 
} 

回答

1

合併在Android的兩個或多個圖像通過使用Canvas其簡單的使用下面的代碼合併圖像, 先創建您要合併其特定圖像的位圖。對於這方面要合併的圖像

獲取的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中設置這個新的位圖。 imageView.setImageBitmap(mNewSaving);

在這種方法二位圖圖像在一個位圖結合

這裏這回新合併的位圖image.Also上sdcard.As保存下面的代碼這一形象

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; 
    } 
} 
0

這裏是合併兩個位圖的正確方法:

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; 
    } 
相關問題