如何将多个图像合并为单个图像,如矩阵? [英] How to merge multiple images into single image like matrix?

查看:95
本文介绍了如何将多个图像合并为单个图像,如矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am working on one application for it I have multiple images and I want to create one image from it. I use the below code for it but the output of the single image is only vertical format.







String sdPath = Environment.getExternalStorageDirectory().getPath()
            + "/MERGE/";
    BitmapFactory.Options options;
    Bitmap bitmap;
    ArrayList<Bitmap> myBitmapList = new ArrayList<Bitmap>();
    int vWidth = 0;
    int vHeight = 0;
    for (int i = 1; i <= 40; i++) {
        try {
            options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            bitmap = BitmapFactory.decodeFile(sdPath + "img" + i + ".jpg",
                    options);
            vWidth = bitmap.getWidth() > vWidth ? bitmap.getWidth()
                    : vWidth;
            vHeight += bitmap.getHeight();
            myBitmapList.add(bitmap);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            options = null;
            bitmap = null;
            System.gc();
            Runtime.getRuntime().totalMemory();
            Runtime.getRuntime().freeMemory();
        }
    }

    Bitmap vTargetBitmap = Bitmap.createBitmap(vWidth, vHeight,
            Bitmap.Config.ARGB_8888);
    Canvas vCanvas = new Canvas(vTargetBitmap);
    int vInsertY = 0;
    for (int i = 1; i < 40; i++) {
        vCanvas.drawBitmap(myBitmapList.get(i), (float) 0f,
                (float) vInsertY, null);
        vInsertY += myBitmapList.get(i).getHeight();
    }

    String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";
    OutputStream os = null;
    try {
        os = new FileOutputStream(Environment.getExternalStorageDirectory()
                .getPath() + "/" + tmpImg);
        vTargetBitmap.compress(CompressFormat.PNG, 50, os);
    } catch (IOException e) {
        Log.e("combineImages", "problem combining images", e);
    }
    Toast.makeText(this, "Done", Toast.LENGTH_LONG).show();







The actual output I want is something like below image.



http://test.vostrel.net/jquery.reel/example/panorama-sprite-local-assets /green-reel.jpg [ ^ ]

推荐答案

为什么不尝试使用GridView。你可以在哪里设置列数= 4(在你的情况下)。

不要在图像之间使用任何填充/边距/间距。
Why don't you try GridView. Where you can set the number of columns = 4 (in your case).
Do not use any padding/margin/spacing between images.


这篇关于如何将多个图像合并为单个图像,如矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆