What is a 9Patch map?

Android system due to the diversity of system and resolution, interface adaptation is a headache for developers, many control slice files are enlarged and stretched on different screens, the edges and corners will blur distortion, very ugly. To make multiple cuts to different resolutions, and increase the size of the installation package. Android created a.9.PNG format to solve this problem. The format, also known as 9Patch maps, allows images to be stretched to specific areas, rather than zooming in and out, ensuring that they look perfect on screens of all resolutions.

How to draw the 9Patch map?

Double-click the draw9patch.bat file to open the following visual interface:

Patch of 9 main interface

2. Add the picture to be drawn

Drag the normal PNG image to be modified to the working area of Draw9Patch, and you can see the following effect:

9Patch operating range

The working area can be roughly divided into three areas, as shown in the figure: red area, green area and blue area.

Red area: the main work area, where future image modification will be done.

Green area: effect display area, used to show the stretch effect of the modified picture. We can see that there are three kinds of stretching effect, from top to bottom are vertical stretching effect, horizontal stretching effect and overall stretching effect.

Blue area: setting area, you can adjust the display effect of the current interface. We can obviously see that there are two drag bars. The upper drag bar named Zoom is used to scale the picture in the red area, while the lower drag bar Patch Scale is used to scale the picture in the green area. Through the Settings of these two drag bars, we can more conveniently modify the picture of the working area, and also understand the display effect after different degrees of stretching in each direction.

Three. Start drawing

If we don’t make any changes to the image, the image will scale as a whole when stretched in all directions. When zooming, the rounded corners of the image will also zoom, resulting in a poor display.

This is what a vertical stretch looks like:

Vertical drawing effect

This is the horizontal stretching effect:

Horizontal drawing effect

To make vertical and horizontal stretching not include rounded corners, we can manipulate the image like this:

Go to the work area, hold down the left mouse button, and draw a horizontal line in the top pixel of the image. The width of this line represents the area of the image stretched horizontally. As shown below:

Horizontal tensile

The light red areas below are the horizontal stretches of the image.

Region of horizontal tension

Similarly, we go to the edge of the image at the far right pixel, hold down the left mouse button and draw a vertical line. The length of this line is the vertical stretch area of the image.

The vertical tensile

The light red area below is where the image will be stretched vertically in the future.

Vertical stretch region

Once we have defined the horizontal and vertical stretch areas through both the top and right edges, the image is free to stretch as we wish. The red area in the figure below is the stretch area. It can be seen that the stretch area does not include four rounded corners, thus ensuring that the rounded corners are not stretched arbitrarily.

Integral stretch region

Note: If you make a mistake in drawing a black line and want to erase the previously drawn content, you can hold down the right mouse button to erase it, or you can hold down the Shift key and use the left mouse button to erase it.

Finally, let’s take a look at the modified image stretching:

Vertical stretching effect:

Modified vertical stretching effect

Horizontal stretching effect:

Modified horizontal stretching effect

Overall stretching effect:

Modified overall stretching effect

4. Save the 9Patch image

Click File in the upper left corner of the tool and select Save 9-Patch to Save the picture.

After saving, the file extension will automatically change to.9.png. Here we have successfully transformed a normal PNG image into a 9Patch image that can be stretched without distortion.

This article is reproduced: bbs.itheima.com/thread-2512…

Only extracted their own use of the place into their own article, there is a need to see the original text.