1. 程式人生 > >Bitmap上下合成圖片

Bitmap上下合成圖片

post rect merge size stat () argb_8888 ase style

合成兩張圖片,上下疊加的效果:

/**
     * 把兩個位圖覆蓋合成為一個位圖,以底層位圖的長寬為基準
     *
     * @param backBitmap  在底部的位圖
     * @param frontBitmap 蓋在上面的位圖
     * @return
     */
    public static Bitmap mergeBitmap(Bitmap backBitmap, Bitmap frontBitmap) {

        if (backBitmap == null || backBitmap.isRecycled()
                
|| frontBitmap == null || frontBitmap.isRecycled()) { return null; } Bitmap bitmap = backBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(bitmap); Rect baseRect = new Rect(0, 0, backBitmap.getWidth(), backBitmap.getHeight()); Rect frontRect
= new Rect(0, 0, frontBitmap.getWidth(), frontBitmap.getHeight()); canvas.drawBitmap(frontBitmap, frontRect, baseRect, null); return bitmap; }

Bitmap上下合成圖片