Android的发展:结合小瓦/位图转换为一个位图 [英] Android Development: Combining small tiles/bitmaps into one bitmap

查看:133
本文介绍了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 };

所以basicly这是一个10 * 10 每一个数字是一个占位符图像(数字)巴纽

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天全站免登陆