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.
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.
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:
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:
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.
Let me know if you have any queries, and do upvote it, if it was helpful to you.
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…
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.
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.
来源:https://stackoverflow.com/questions/7426518/bad-patches-in-9-patch-file