Combine Images in android

前端 未结 2 1685
猫巷女王i
猫巷女王i 2021-02-10 06:36

how to merge two images in android by programming in java and save in external SD Card or some where else.

2条回答
  •  终归单人心
    2021-02-10 06:51

    Try below code

    private Bitmap joinImages(File first, File second)
    {
        Bitmap bmp1, bmp2;
        bmp1 = BitmapFactory.decodeFile(first.getPath());
        bmp2 = BitmapFactory.decodeFile(second.getPath());
        if (bmp1 == null || bmp2 == null)
            return bmp1;
        int height = bmp1.getHeight();
        if (height < bmp2.getHeight())
            height = bmp2.getHeight();
    
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth() + bmp2.getWidth(), height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp1, 0, 0, null);
        canvas.drawBitmap(bmp2, bmp1.getWidth(), 0, null);
        return bmOverlay;
    }
    

提交回复
热议问题