My designer works on Illustrator and exports all the resources for mdpi, hdpi and xhdpi (and also for iOS res) with a script. For buttons and streachables images, I'm looking for the best solution to generate the 9patches.

Until now, I was using the draw9patch soft in the SDK to generate the 9patches. It still works, but seriously, I hope that there is a better way. If in my project I have 20 buttons, with 3 or 4 states, and in 3 density types, I can't imagine the hours that this solution will require.

A solution would be to use the Asset Studio tool, but I don't want to provide my xhdpi file, and get poorly generated images for the other density folders. My goal is to get pixel perfect 9patches for each density.

We also tried to use SVG files for stretchable images, but it seems that Asset Studio doesn't accept them.

If my designer tries to make the 9patch directly in Illustrator, he can't use the script to export, because the 1 px line will be scaled too, and won't measure 1px anymore.

So is there a solution to make 9patches, without losing image quality, and without spending ten hours for it ?

Ok I checked it and it's definitely better than the draw9patch tool. Too bad that with the free version we can't actually test the batch tool, not even one time. I wonder how it handles density folders. I'll try to get more info on this, and buy it if there is no other better ways.
–
ChayyJul 17 '12 at 13:52

1

Ok, so I bought it, and the batch feature is really great. I can work on one image, and then apply this in one click to all my button states, and in each density types. I think that my designer will prefer to find a way in his side with Illustrator, but this tool will still be useful for me.
–
ChayyJul 24 '12 at 8:50

You probably helped me more testing it, than I helped you finding;) Thanks!
–
Michał KJul 24 '12 at 9:05

My solution is to spend a ton of hours learning draw9patch, and then it won't take hours to make the buttons. I did this myself, and suffered, but draw9patch is a really simple way to do it, and each image (for buttons) takes me no more than 15 seconds. draw9patch images should are great because you really only have to do them once, and they will work with all densities, as they will stretch accordingly. If you have text in your images then you have another problem. This is frowned upon because you lose the ability to translate your application with a simple stings.xml

My solution:

1. Get awesome at draw9patch

2. Don't use image's with text. draw9patch can be used to center the text of a button correctly and this will increase the ability of your app to be used in different languages. Something that can easily boost your download/sales. This is important, because even if you give your app the ability to target one more language (let's say... Spanish) then it really makes that target audience happy.

I already made tons of 9-patches with the draw9patch tool, and I don't think that we spend hours learning how to use it, it's pretty straightforward, but we spend hours on actually using it... Try one of the tools given in the other answers and you'll see. Also "draw9patch images should are great because you really only have to do them once, and they will work with all densities, as they will stretch accordingly." is wrong. 9-patches don't solve the density "issue", if you don't provide a 9-patch in each density folder, your 9-patch will be scaled, and you'll get artifacts or blurry images.
–
ChayyJul 24 '12 at 9:09

Here is good nine-patch editor, that save for me tons of time: download jar link and some description. The greatest feature is "copy-paste" function, that allows provide the same stretchable areas for images in different state really fast.

I don't think there is some editor that allows works with different image sizes, because there can be significant difference for different screen sizes.

I didn't know this soft, I think it's great. But the better9-patch-tool also has all theses features, plus a batch feature that allows me to work on one image, and affect it to a folder of images. Apart from that, I prefer the GUI of your tool.
–
ChayyJul 24 '12 at 8:45

Yeah, I bought better9patch-tool, but don't like it at all... The GUI sucks and I hate that those lines are continous, not pixel by pixel (makes it impossible to have one pixel stretchable area which is often desired). This one looks better
–
Michał KSep 14 '12 at 10:29

I zip through my 9-patch generation by opening each image to be 9patched in an Image Editor (Photoshop / Paint .NET) and then increasing the canvas size by 2 on both dimensions.

Once you've done this you can draw in your stretch and padding lines quick time. It's a bit of a pain if you're doing it for 100's of images but it only need's to be done once per project. I can't imagine many projects where there would be that many 9-patches for it to take that much time at all...

If you really want to streamline the proccess you can remove the padding indicators from your 9patch and add them to your view's using the style attribute...

If my designer tries to make the 9patch directly in Illustrator, he can't use the script to export, because the 1 px line will be scaled too, and won't measure 1px anymore.

This line worries me - you shouldn't be scaling up mdpi images to hdpi, their wouldn't be any point. If there is only an mdpi image available it will use it and scale it automatically at runtime.

Like I said, I have 20 - 25 buttons that need 9-patches, for each state and each density type. It's a big project, and the design will probably evolve a bit, so I need something quicker than this method. Regarding the 1 px line thing, he works in vector.
–
ChayyJul 17 '12 at 13:24

If you have 20-25 styles of buttons in the same app, unless you're doing some sort of user determined themeing, you might want to reconsider...
–
GraemeJul 17 '12 at 14:06

Well, buttons + other components that need 9patches. Yep 2 types of users in the app, with some differences in the themes. And around 80 activities
–
ChayyJul 17 '12 at 14:30

Still seem's pretty high - I would have imagined 3 styles of buttons per user MAX otherwise I don't know how you're keeping a uniform feel across your app, but that's all you and not me. Good luck with it! Hope you find a reasonable program to get it done with.
–
GraemeJul 17 '12 at 14:36

I am using 9 patches mainly to draw backgrounds for buttons and other views. Most of them are single color backgrounds with some kind of 2 pixel separators and some of them are gradients with separators as well. I am putting them in the res\drawable-nodpi folder which is a special folder that instructs android not to perform any scaling to its contents.

So far I have the expected results with no problems at all. My 2 pixel separators are 2 real device pixels (not density pixels) in several devices from ldpi to hdpi resolutions which is what I want.

Thx, I use this sometimes too. But for a more complex image like we can have for the system buttons, we need to provide the 9-patch in each density folder, whereas it will appear blurred.
–
ChayyJul 18 '12 at 8:32