2011-07-14 13 views
2

草、水、アスファルトなどの小さな画像を1つのビットマップにまとめようとしています。Android開発:小さなタイル/ビットマップを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 }; 

のでbasiclyこれは10 * 10 あるすべての数は

を.pngの画像(数)のプレースホルダですしかし、どのように私は一緒にマージしますか?

//サイモン

+0

詳細情報を提供したい場合があります。たとえば、必要な列数/行数、イメージをマージする順番などです。それらを横に並べて、あるいは別のものに組み合わせてほしいですか? – hwrdprkns

+0

それは10 * 10で、はい、ポケモンのようにサイドサイドになるはずです。 注文は指定された配列 – carefacerz

+0

これは簡単ではありません。 'View'をサブクラス化してこの配列をコンストラクタに渡してから、あなたが望むように10のビューを作成するだけではるかに早くなるかもしれません。そうすれば、いつでも簡単に並べ替えることができます。 – hwrdprkns

答えて

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

こんにちは、私はループ1を使用しようとしましたが、大きなビットマップは最初の要素を1つだけ描画します。詳細:http://stackoverflow.com/questions/21044984/android-combine-many-bitmaps-to-one-large-one-goes-wrong-and-cant-recycle-bitma?noredirect=1#comment31640898_21044984 – lolyoshi

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

Unfortuntllyない。 10種類異なっています。どんな助け? – carefacerz

+0

ちょっと混乱していますが、それぞれの画像のサイズが異なる場合、マップの幅と高さをどのように維持しますか?キーは、描画を開始する前にマップの大きさを知ることです。 –

関連する問題