Sunday, April 1, 2012

Android's NinePatch: Better Stretchable Images than iOS

A friend of mine this week told me about NinePatch, a nice image file format developed as part of Android.

A good overview of NinePatch can be found here. It is basically a PNG with extra information included to identify the "stretchable" areas of the image. Android then handles the resizing (and proper stretching) automatically for you.

This is great because it frees the programmer from having to write any code related to stretchable images.

It also adheres to the DRY principal (Don't Repeat Yourself) because all the image information is stored in one place: the image (where it belongs) instead of in two places (the image and the code). This allows a designer, for example, to update the image without requiring any software changes.

iOS doesn't yet have an equivalent to NinePatch but it turns out that there is an open source library that brings NinePatch support to iOS. Here is the announcement from the developer Tortuga 22.

In addition to code improvements another potential benefit to adopting NinePatch might be to increase the image asset reuse between your Android and iOS apps.

I haven't yet tried this myself but hope to soon.

No comments: