When scaling a shape, those with corner styles will be distorted and displayed. With 9 slices, you can scale the shape while maintaining its original shape by dividing the shape into 9 areas.
Generates an image corresponding to 9 slices. Use Android Asset Studio published by Romannurik. Select Simple nine-patch generator from the top screen and create an image as shown below.
Introduce pillow and nine-patch
pip install pillow
pip install ninepatch
Create a Ninepatch object with the 9-slice image generated above as an argument. Use the render () method to specify the vertical and horizontal sizes to enlarge the image.
nineSliceTest.py
from ninepatch import Ninepatch
from PIL import Image
bubble = Ninepatch("bubble.9.png ")
scaledBubble = bubble.render(600,200)
scaledBubble.show()
The original image
Result image
Recommended Posts