Android 开发:将小图块/位图组合成一个位图 [英] Android Development: Combining small tiles/bitmaps into one bitmap

查看:28
本文介绍了Android 开发:将小图块/位图组合成一个位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我所有的小图像,如草、水和沥青等,整合到一张位图中.

Im trying to get all my small images like grass, water and asphalt and so on, into one bitmap.

我有一个像这样的数组:

I have an Array that goes like this:

public int Array[]={3, 1, 3, 3, 1, 1, 3, 3, 3, 3, 
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
            1, 1, 1, 1 ,1 ,1, 1, 1 ,1 ,1 
            ,7 ,7 ,7, 7, 7 ,7, 7 ,7 ,7, 7 
            ,7 ,7 ,7 ,7, 7 ,7, 7 ,7 ,7 ,7 
            ,7 ,7 ,7 ,7, 7, 7, 7, 7 ,7 ,7 
            ,7 ,7 ,7 ,7, 7, 7 ,7 ,7 ,7 ,7 
            ,7 ,7 ,7 ,7, 7, 7, 7 ,7 ,7, 7 
            ,6, 6, 6, 6, 6 ,6 ,6, 6, 6 ,6 
            ,6, 6, 6 ,6, 6, 6 ,6, 6 ,6 ,6 };

所以基本上这是一个 10*10每个数字都是一个图像(数字)的占位符.png

So basicly this is a 10*10 Every number is a placeholder for a image(number).png

但是我如何将它们合并在一起?

But how do i merge them together?

//西蒙

推荐答案

好的,下面的代码片段应该并排组合两个图像.我不想推断 10,但我相信你会自己找出 for 循环.

Okay so the following snippet should combine two images side by side. I didn't want to extrapolate for 10, but I'm sure you'll figure out the for loops by yourself.

public Bitmap combineImages(Bitmap c, Bitmap s) {
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) { 
      width = c.getWidth() + s.getWidth(; 
      height = c.getHeight()); 
    } else { 
      width = s.getWidth() + s.getWidth(); 
      height = c.getHeight(); 
    } 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 

    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, c.getWidth(), 0f, null); 
    //notice that drawing in the canvas will automagically draw to the bitmap
    //as well
    return cs; 
  } 

这篇关于Android 开发:将小图块/位图组合成一个位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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