Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create 9 patch in Photoshop? What is 9.png encoding? [closed]

Provided utility looks bad, for example it does not allow to do "Save As", or to draw several button states with similar slicing.

Is it possible to draw 9.png in photoshop? I noticed, that generated png just contains black pixels in outer edge. Is this what is marking the slices?

What if black pixels present in two opposite edges, how does this work?

Are outer edges cut off when displayed on android?

like image 974
Suzan Cioc Avatar asked May 18 '12 13:05

Suzan Cioc


People also ask

What is 9 patch PNG?

A 9 patch image is a regular png (. PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image.

What is the difference between a regular .PNG and a nine patch image?

`A 9-patch image is a standard PNG image that includes an extra 1-pixel-wide border and must be saved with the extension .

How do I create a 9 PNG file?

In Android Studio, right-click the PNG image you'd like to create a NinePatch image from, then click Create 9-patch file. Type a file name for your NinePatch image, and click OK. Your image will be created with the . 9.


1 Answers

Yes, I do all of my nine patches in Photoshop. Here are the basic rules for creating a 9-patch:

  1. The outer 1px margin can contain only 100% black (RGB 0, 0, 0) or fully transparent.

  2. The black pixels for the top margin and left margin define the stretch points, and must be either a solid line, a single point, or two separate points. If two points are defined, it will stretch equally between the two.

  3. The black pixels for the bottom margin and right margin define the content area. These pixels must be one contiguous line.

  4. When saving, be sure to append the .9.png extension.

Hope this helps. :)

EDIT: And yes, those will not be displayed when used in your layouts, provided it's properly formatted and you've saved it as a .9.png.

enter image description here

enter image description here

Okay, so the top would be a simple nine patch for a spinner. the lines across and down in the second image show which rows/columns of pixels would be duplicated. The blue rectangle in the second image shows the area in which Android would allow content to be placed. So text, for example, would simply wrap to stay inside this rectangle.

like image 60
Kevin Coppock Avatar answered Nov 05 '22 08:11

Kevin Coppock