Android Development: Combining small tiles/bitmaps into one bitmap

后端 未结 2 1287
余生分开走
余生分开走 2021-01-21 15:32

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         


        
2条回答
  •  有刺的猬
    2021-01-21 16:06

    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; 
      } 
    

提交回复
热议问题