2013-04-23 89 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; 
    }