2

草、水、アスファルトなどの小さな画像をすべて 1 つのビットマップにまとめようとしています。

次のような配列があります。

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

しかし、どうすればそれらをマージできますか?

//サイモン

4

2 に答える 2

6

次のスニペットは、2 つの画像を並べて結合する必要があります。10 を外挿したくなかったのですが、for ループについては自分で理解できるはずです。

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; 
  } 
于 2011-07-14T15:43:18.800 に答える
0

すべてのタイルが同じサイズの場合は、1 つの大きなタイルを作成Bitmapして、すべてのタイルを適切な場所に描画できます。例えば:

private static final int MAP_WIDTH = 10; // in tiles
private static final int MAP_HEIGHT = 10;
private static final int TILE_WIDTH = 10;
private static final int TILE_HEIGHT = 10;

public Bitmap createMap() {
    Bitmap mainBitmap = Bitmap.createBitmap(TILE_WIDTH * MAP_WIDTH, TILE_HEIGHT * MAP_HEIGHT,
            Bitmap.Config.ARGB_8888);
    Canvas mainCanvas = new Canvas(mainBitmap);
    Paint tilePaint = new Paint();
    for (int i = 0; i < map.length; i++) {
        // Grab tile image (however you want - don't need to follow this)
        Bitmap tile = BitmapFactory.decodeResource(getResources(), getResources()
                .getIdentifier(String.valueOf(map[i]), "drawable", "your.package"));

        // Draw tile to correct location
        mainCanvas.drawBitmap(tile, (i % MAP_WIDTH) * TILE_WIDTH,
                (i / MAP_WIDTH) * TILE_HEIGHT, tilePaint);
    }
    return mainBitmap;
}
于 2011-07-14T16:19:12.647 に答える