Skip to content
Product and web UIguide

How to crop one icon from a raster sprite sheet

By SkeuDesign Editorial Team1 min read

Answer in brief

Use the nine-argument form of drawImage to select a source rectangle and paint it into a destination rectangle. Keep source coordinates in the sheet's image coordinate system.

Extract the third tile

For a sheet of 32-pixel tiles in one horizontal row without gutters, the third tile begins at x=64 and y=0. Select 32 by 32 source pixels and draw them into the required output square. Adjust the offset for any padding between tiles.

Include borders in the coordinate calculation

With a one-pixel outer border and a two-pixel gutter, 32-pixel tiles begin at x=1, 35 and 69. Draw the third tile from x=69. Inspect an enlarged crop for a line from the adjacent tile, especially after moving from a tightly packed source sheet to a padded export.

Sources

  1. [1] CanvasRenderingContext2D: drawImage() method - Web APIs — MDN Web Docs, accessed November 23, 2026

Frequently asked questions

Why is part of the next tile visible?

Inspect the tile stride, gutter and source rectangle. The distance between tile origins may exceed the tile width.