在水平android中将多个图像合并为一个

时间:2016-11-11 21:32:49

标签: android merge android-bitmap

我正在使用camera2 api将多个图像捕获为一个,之后我保存图像并创建全景图像

private Bitmap combineImageIntoOne(ArrayList<Bitmap> bitmap) {
        int w = 0, h = 0;
        for (int i = 0; i < bitmap.size(); i++) {
            if(i < bitmap.size() - 1){
                h = bitmap.get(i).getHeight() > bitmap.get(i + 1).getHeight() ? bitmap.get(i).getHeight() : bitmap.get(i + 1).getHeight();
            }
            w += bitmap.get(i).getWidth();
        }

        Bitmap temp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(temp);
        float aspectRatio = 0;
        int side = 0;
        int width = 0;
        for (int i = 0; i < bitmap.size(); i++) {
            Log.d("HTML", "Combine: "+i+"/"+bitmap.size()+1);
            side = (i == 0 ? 0 : side+bitmap.get(i).getWidth());
            canvas.drawBitmap(bitmap.get(i), 0f, side, null);
        }
        return temp;
    }
如果有人知道如何处理水平图像合并20个项目,那么缩小它会变得更难吗?你用什么代码来解决这个问题?

1 个答案:

答案 0 :(得分:0)

  private Bitmap mergeMultiple(ArrayList<Bitmap> parts) {

        int w = 0, h = 0;
        for (int i = 0; i < parts.size(); i++) {
            if (i < parts.size() - 1) {
                w = parts.get(i).getWidth() > parts.get(i + 1).getWidth() ? parts.get(i).getWidth() : parts.get(i + 1).getWidth();
            }
            h += parts.get(i).getHeight();
        }

        Bitmap temp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(temp);
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        int top = 0;
        for (int i = 0; i < parts.size(); i++) {

            top = (i == 0 ? 0 : top + parts.get(i).getHeight() + 100);
            canvas.drawBitmap(parts.get(i), 0f, top,paint );
        }
        return temp;

    }