android:多个bitmap横向、纵向拼接成一个

一、横向(两个)

/** 
* 横向拼接 
* <功能详细描述> 
* @param first 
* @param second 
* @return 
*/ 
private Bitmap add2Bitmap(Bitmap first, Bitmap second) { 
int width = first.getWidth() + second.getWidth(); 
int height = Math.max(first.getHeight(), second.getHeight()); 
Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888); 
Canvas canvas = new Canvas(result); 
canvas.drawBitmap(first, 0, 0, null); 
canvas.drawBitmap(second, first.getWidth(), 0, null); 
return result;

}

二、纵向(两个)

/**
* 纵向拼接
* <功能详细描述>
* @param first
* @param second
* @return
*/
private Bitmap addBitmap(Bitmap first, Bitmap second) {
int width = Math.max(first.getWidth(),second.getWidth());
int height = first.getHeight() + second.getHeight();
Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.drawBitmap(first, 0, 0, null);
canvas.drawBitmap(second, 0, first.getHeight(),null);
return result;
}

三、纵向(多个)

/**
 * 将bitmap集合上下拼接
 *
 * @return
 */
private Bitmap drawMulti(ArrayList bitmaps) {
    int width = bitmaps.get(0).getWidth();
    int height = bitmaps.get(0).getHeight();
    for (int i = 1;i 
 

你可能感兴趣的:(android基础)