Created
December 3, 2014 12:08
-
-
Save meki/8bbd374f8284f84828c5 to your computer and use it in GitHub Desktop.
Canvas を使ってタイル画像を敷き詰める ref: http://qiita.com/_meki/items/a9a465d1d03c0340ad25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* タイル画像をキャンバス上に敷き詰める. | |
* @param canvas 描画用キャンバス. | |
* @param resource リソースオブジェクト. | |
* @param resourceId タイル画像のリソースID. | |
*/ | |
public static void fillByTile(@NonNull Canvas canvas, | |
@NonNull Resources resource, | |
@DrawableRes int resourceId) | |
{ | |
int canvasWidth = canvas.getWidth(); | |
int canvasHeight = canvas.getHeight(); | |
Bitmap tile = BitmapFactory.decodeResource(resource, resourceId); | |
int tileWidth = tile.getWidth(); | |
int tileHeight = tile.getHeight(); | |
for (int y = 0; y < canvasHeight; y += tileHeight) | |
{ | |
for (int x = 0; x < canvasWidth; x += tileWidth) | |
{ | |
canvas.drawBitmap(tile, x, y, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment