android bitmap拼接

android bitmap拼接

一个简单的拼接方法

//bitmaps 需要拼接的图片,按顺序传入

public static Bitmap mosaicBitmapVertical(@NonNull Bitmap... bitmaps) {

    int height = 0;
    for (int i = 0; i < bitmaps.length; i++) {
        height += bitmaps[i].getHeight();
    }
    int width = 0;
    for (int i = 0; i < bitmaps.length; i++) {
        if (width < bitmaps[i].getWidth()) {
            width = bitmaps[i].getWidth();
        }
    }
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    int drawHeight = 0;
    for (int i = 0; i < bitmaps.length; i++) {
        canvas.drawBitmap(bitmaps[i],0,drawHeight,null);
        drawHeight += bitmaps[i].getHeight();
    }
    return result;
}

这个是竖直拼接,水平拼接照着简单改一下就好

你可能感兴趣的:(android-开发,工具方法)