Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@meki
Created December 3, 2014 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meki/8bbd374f8284f84828c5 to your computer and use it in GitHub Desktop.
Save meki/8bbd374f8284f84828c5 to your computer and use it in GitHub Desktop.
Canvas を使ってタイル画像を敷き詰める ref: http://qiita.com/_meki/items/a9a465d1d03c0340ad25
/**
* タイル画像をキャンバス上に敷き詰める.
* @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