android将两张图片合并为一张图片

合成两张图片

通过canvas绘制合成

private Bitmap mergeBitmap(Bitmap firstBitmap, Bitmap secondBitmap) {
        int w1 = firstBitmap.getWidth();
        int h1 = firstBitmap.getHeight();
        int w2 = secondBitmap.getWidth();
        int h2 = secondBitmap.getHeight();
        int space = 20;
        Bitmap bitmap = Bitmap.createBitmap(w1, h1 + h2 + 40,
                firstBitmap.getConfig());
        Canvas canvas = new Canvas(bitmap);
        canvas.drawRGB(255, 255, 255);
        canvas.drawBitmap(firstBitmap, new Matrix(), null);
        int left = w1 - w2 > 0 ? ((w1 - w2) / 2) : 0;
        canvas.drawBitmap(secondBitmap, left, h1 + 20, null);
        return bitmap;
    }

代码很简单,代码是将两张图片上下衔接。

    原文作者:Jabony
    原文地址: https://blog.csdn.net/knockheart/article/details/104375486
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞