9tool is a simple command line tool to make it a little bit easier to work with Android nine patch (.9.png) files.

The main use case is to copy the nine patch area from one nine patch file to another one, which may also be a plain .png file. When you copy the nine patch area to a normal .png it becomes a .9.png.

9tool has some crude dpi detection and will scale the nine patch area from different densities. The detection currently works by looking at the folder name, but it's also possible (or required) to specify the dpi on the command line.

9tool can also strip the nine patch area to create a normal .png from a .9.png file.

Quick usage

It's recommended that you add 9tool to your system path. 9tool has two commands, either copy or png.

Here are some examples:

<pre> 9tool copy source.9.png dest.png </pre>

Would copy the nine patch area from source.9.png to dest.png. After copying dest.png will be renamed to dest.9.png.

<pre> 9tool copy drawable-xhdpi/source.9.png drawable-mdpi/source.9.png </pre>

Same as above, but would scale down the nine patch area, assuming that source.9.png are the same image asset (there's no checking!). If the destination source.9.png does not exist, it will be created based on a scaled down version of the source file.

<pre> 9tool png patch.9.png </pre>

Would "unpatch" patch.9.png and rename it to patch.png.