Convert png images to 9 patch in Android Studio
Solution 1
Well I don't think there is any tool in Android Studio
but you can do this by Android Asset Studio
Android Asset Studio Simple Nine-patch Generator
This is a very handy tool to create simple 9 patch
images for all dpi
with a clean user interface.
Solution 2
If you rename the resource from *.png
to *.9.png
then in Android Studio you may edit it with 9 patch (a tool provided with the Android SDK).
Solution 3
Android Studio now has this option available by right-clicking on the image file in your res folder, then selecting Create 9-Patch file
. You can then open the newly created 9-patch file and start editing!
Solution 4
Update: Android Studio now has a feature that can be used to generate 9patch images.
To do this navigate to /home/android-studio/data/sdk/tools
on your terminal
and run draw9patch
.
user2392650
Updated on May 19, 2020Comments
-
user2392650 almost 4 years
In android studio,you can edit 9 patches directly from with the IDE. But is it also possible to convert an png image to 9-patch using the IDE? (similar to the android 9-patch tool provided by the SDK).
-
user2392650 almost 11 yearsThanks Vipul!. Seems like a very glaring omission the android studio. How can we request for this feature to be added.
-
dmSherazi over 10 years@vipul the link is very helpful
-
Reinstate Monica about 9 years@Paschalis You're correct. When I renamed the file manually, Android Studio initially recognised it and let me edit it as a 9 patch image, but it wouldn't compile. The name contained illegal characters, I'm guessing the full stop. CodeMonkey's answer worked though.
-
Raja Jawahar over 8 yearsCopy your image and put into drawable folder and just right click on that one, you will get the option Create a 9 patch
-
Anis LOUNIS aka AnixPasBesoin over 7 yearsIt's possible nowadays with Android studio. Right click on your png, make it a 9 patch and then double click on it and the magic will happen.
-
Arnold Brown over 5 yearsthe image created successfully but the image contain black borders