b2KIT

9-Patch Image Generator

Create Android 9-patch images with stretchable regions for button backgrounds.

Tested tool guide Tested browser tools Checked August 16, 2026

What 9-Patch Image Generator does, with a checked example

This tool takes an image you provide, lets you mark which rows and columns should stretch when Android resizes the drawable, and lets you mark a separate content-padding box for where text or child views should sit. On export it adds the mandatory 1-pixel border and writes the black marker pixels Android's resource compiler reads at build time, then saves the file with the .9.png extension the platform requires. The detail people miss most: if you skip the padding marks (bottom and right edge) entirely, Android does not leave padding undefined - it defaults to match the stretch region marked on the top and left edge, so a plain button often needs only the stretch marks drawn to get sane content padding for free. Draw explicit padding marks only when the content box needs to differ from the stretch region.

Worked example

A concrete input and expected output from the current implementation.

Input

a flat 20x20px blue square PNG, with the middle row and middle column each marked as the single stretchable region, and no content padding set

Expected output

a 22x22px PNG - the original 20x20 artwork centered, surrounded by a 1px transparent border - with a single black pixel at the top edge above the marked column and a single black pixel at the left edge beside the marked row; the bottom and right edges stay fully transparent because no padding was set

9-patch format always adds exactly 1px on each side; black segments on the top/left border tell Android which pixel columns/rows to repeat when stretching, and an all-transparent bottom/right border means content padding defaults to the same as the stretch region.

How the result is produced

1

Border marker encoding

The exported file is always the source image plus 1 pixel on every side. Black pixels placed along the new top and left edges mark which columns and rows are allowed to stretch; black pixels along the new bottom and right edges mark the content padding box other views should respect. Every other border pixel must stay fully transparent, or the Android build tool will reject the drawable.

2

Region marking and export

You draw the stretch and padding segments directly against the source image in the editor rather than hand-placing pixels. The interior artwork is never altered - only the added border is written to. On export the tool flattens your markings into that border and writes a standard PNG named with the .9.png suffix, ready to drop into an Android res/drawable folder.

Good uses

  • building a button or dialog background that needs to stretch cleanly across different text lengths and screen sizes
  • converting a rounded-rect or gradient graphic into a resizable Android drawable without installing Android Studio
  • fixing or re-marking an existing 9-patch asset's stretch and padding regions before re-exporting it

Limits and checks

  • the output is only meaningful to Android's resource pipeline - opening it in a generic image viewer just shows a bordered PNG with visible black tick marks, not a preview of the stretch behavior
  • if you mark more than one stretch segment on the same edge, Android divides extra space across those segments rather than distributing it evenly by default, which can surprise you if you expected symmetric stretching
  • stretch marks (top/left) and content padding marks (bottom/right) are drawn separately, but leaving padding unmarked isn't the same as leaving it undefined - it defaults to the stretch region bounds, so only draw explicit padding marks when the content box needs to differ from where the artwork stretches

Common questions

Can I just rename a normal PNG to .9.png instead of using this?

No. Android's build tool looks for actual black marker pixels in a real 1px border; a renamed ordinary PNG has no such border and will either fail to compile as a resource or render as a plain non-stretching bitmap. This tool generates the required border pixels for you.

Will the exported file work as a background in Jetpack Compose?

It works as a classic Android drawable resource for View-based UI (backgrounds, ImageView). Compose's support for rendering nine-patch stretch behavior directly varies by version and setup, so if you're targeting Compose, verify against your current Compose version before relying on it.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools