首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android将数据库中的多张图片合并为一张位图

Android将数据库中的多张图片合并为一张位图
EN

Stack Overflow用户
提问于 2014-05-28 14:01:18
回答 1查看 447关注 0票数 2

我需要将多个图像组合成一个位图。我需要组合在2-6范围内的图像。图像的路径取自我的应用程序数据库,图像存储在我的外部SD卡中。我已经合并了2张图片。但我需要组合3,4,5和6个图像到单一画布。

我的两张图片的合并代码如下:

代码语言:javascript
复制
private Bitmap combineImageIntoOne(ArrayList<Bitmap> a) {
        int top = 0;

        int width = 0, height = 0;
        for (int j = 0; j < a.size(); j++) {
            width += a.get(j).getWidth();
        }
        height = a.get(0).getHeight();
        Bitmap combineBitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        Canvas comboImage = new Canvas(combineBitmap);
        for (int i = 0; i < a.size(); i++) {

            System.out.println("image width = " + top);
            comboImage.drawBitmap(a.get(i), top, 0f, null);
            top = top + a.get(i).getWidth();
        }
        System.out.println("combineBitmap combineBitmap..in.."+combineBitmap);
        return combineBitmap;
    }
EN

回答 1

Stack Overflow用户

发布于 2014-05-28 14:24:50

我认为你可以用同样的代码把3,4,5和6张图片组合到一张画布上。

如果你想使用最高的位图的高度,你可以像这样修改代码。

代码语言:javascript
复制
//get the max height 
    height = a.get(0).getHeight();
    for (int j = 0; j < a.size(); j++) {
        width += a.get(j).getWidth();
        if(height<a.get(j).getHeight()){
            height=a.get(j).getHeight();
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23903863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档