27
2017
09

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

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

上一篇:MapKit 进阶教程: 自定义瓦片 下一篇:Android开发艺术探索阅读笔记之二:Android的消息机制