Bad 'Patches' in 9-Patch File
Asked Answered
M

6

27

I'm attempting to use the Draw9Patch tool from the Android SDK, but immediately upon opening my image with Draw9Patch it shows all of my image area as a 'Bad Patch.' I manually drew in the lines that define the stretchable areas, however I am unsure if this will work properly. Could someone explain why this specific image is not a 'good patch'? Other Stackoverflow answers to this question do not seem to correlate to my problem or I am not understanding them.

Example of Draw9Patch Bad Patches Original Image

Motheaten answered 15/9, 2011 at 6:6 Comment(3)
The "bad patch" thing is definitely confusing, but won't stop your drawable from working. The dev sites says it's basically a warning that those patch sites "may produce artifacts in the graphic when stretched". If you look at a lot of the stock Android drawables you'll see that they contain "bad patches". So just test them out and if they look fine I wouldn't worry about it.Emmott
That's actually the answer I recently discovered. You should post it as an actual answer instead of a comment and I'll mark it as Accepted (since the other answers were misleading).Motheaten
PureSpider's answer is correct. Nor sure if you can re-accept the right answer. Your image has gradients. All you need is stretch over 1 or few pixels to maintain that gradient. It WILL help eliminating those Bad Patches esp with new bigger screens like HTC One X and Galaxy S3, you will see the difference.Jarnagin
E
27

Old, but I had the same question. The "bad patch" thing is definitely confusing, but won't stop your drawable from working. The dev sites says it's basically a warning that those patch sites "may produce artifacts in the graphic when stretched"‌​.

If you look at a lot of the stock Android drawables you'll see that they contain "bad patches". So just test them out and if they look fine I wouldn't worry about it.

Emmott answered 25/11, 2011 at 0:42 Comment(0)
D
17

Late answer but it seems the 9patch tool is analyzing if your stretched area varys in its pixels, meaning one strip is different from the others in the stretchable area, which may produce ugly stretching artifacts if done accidentally.

I made a small (ugly) example to visualize that:
In the first image, there are no bad patches (apart from the center one, ignore that).
That is because the stretched area is all of the same color, the pixel strips are all the same: No bad patches shown

In the second image however, the top and bottom parts are also marked as bad because the gradient starts there and the horizontal pixel strips are not the same as the rest anymore (they contain a bit more blue/red), which COULD cause artifacts if used unpurposely: Bad patches created

Dermott answered 9/6, 2012 at 20:30 Comment(0)
P
11

I have found the best and the simplest answer to make 9-patch image.

From HERE you can make a 9-patch image for all the resolutions - XHDPI, HDPI, MDPI, and LDPI in just one click.

enter image description here

Paronymous answered 31/5, 2013 at 7:11 Comment(0)
L
3

I have just published a Medium post about Bad Patches. It explains the underlying logic for bad patches and contains some advices on conquering them. Feel free to check it out:

9-patch: bad patches everywhere…

bad patches

Lubricate answered 1/4, 2016 at 12:22 Comment(0)
G
2

I am thinking your border is likely the issue:

From developer.android.com:

"The border is used to define the stretchable and static areas of the image. You indicate a stretchable section by drawing one (or more) 1-pixel-wide black line(s) in the left and top part of the border (the other border pixels should be fully transparent or white). You can have as many stretchable sections as you want: their relative size stays the same, so the largest sections always remain the largest."

It looks like you have padding boxes, but without space between your image and the boxes. That means that Android probably interprets them as borders, rather than as padding boxes (I believe).

Try making a 1-pixel BLACK border around your image. Padding boxes are optional, but should be separated from the image by some transparent pixels.

Mostly, I recommend trying to come as close to the examples you find here as possible.

Hope that helps.

Gielgud answered 15/9, 2011 at 8:26 Comment(1)
I added a 1-pixel black border around the image, but that did not change the result.Motheaten
D
1

You should try defining a one pixel stretch area on your button. You don't have a gradient effect, so the result will be the same. The bad patch is usually generated by the left side stretch definition.

Depressor answered 22/3, 2012 at 13:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.