Reputation: 581
Whenever I try to add a 9-patch image to the \drawable
folder in my project, I get the same error:
ERROR: 9-patch image C:\...\res\drawable\appwidget.9.png malformed.
Frame pixels must be either solid or transparent (not intermediate alphas).
Found at pixel #3 along top edge. Failure processing PNG image
C:\...\res\drawable\appwidget.9.png
The weird thing in this example is that I've got this image from the "android-g1-icon" images found in the SDK resources, so it is supposed to be OK. The same happened with any 9-patch image I've tried so far. What could be wrong?
Upvotes: 58
Views: 64176
Reputation: 707
This is the problem with the latest ADT that is 20.0.3. You can instead rename the *.9.png to *.png and start working.
I think this is the bug with the ADT only, since for 18.0.0 version ADT it doesn't prompt for this type of error and works fine.
Upvotes: 23
Reputation: 595
I have resolved it by changing the stretch scope in Android Studio.
Upvotes: 0
Reputation: 1
When we nine patch any image it creates a black line to its border. That border should be transparent or completely solid. If it is not, this error will come.
So the solution is to increase the width and height by two pixels. (In Photoshop increase the size of the canvas, not the image.)
Upvotes: 0
Reputation: 4981
Your 9-patch can be wrong.
Maybe you strip 9-patches one-pixel borders away and information gained from them is not available. Try to add a bottom line and a right line for text too. I think it will help to solve your problem.
Upvotes: 1
Reputation: 520
Now there are two PNG crunchers in the Android build tool, AAPT and a Java cruncher. Both checks for malformed 9 patch images.
I've looked into the source code of the build tool. There is no option to disable compression on 9 patch image or ignore malformed ones. At least not options available to users.
So here is a simple script to replace AAPT:
https://gist.github.com/ksc91u/37513796b2cec37bb3c5
When called to compress a 9 patch image, it will simply copy the file, otherwise, it will launch the real AAPT with @ARGV.
Upvotes: 4
Reputation: 4764
I found the issue is about *.9.png files. Open and check all your 9-Patch files, make sure that all files have black 1 pixel wide border, if don't have, just click the white place and add it, then save it.
It's the only solution to my problem.
Upvotes: 0
Reputation: 519
If you are making the image using an online generator tool, then you must remove any special characters from the name for it to work.
Upvotes: 2
Reputation: 594
I have encountered with same problem on Android Studio:
AAPT out(943142208) : No Delegate set : lost message:Done
AAPT err(943142208): ERROR: 9-patch image /Users/cartman/Github/UteacherAndroid/RefactorDemo/app/src/main/res/drawable-xxhdpi/nav_shabow.9.png malformed.
AAPT err(943142208): Frame pixels must be either solid or transparent (not intermediate alphas).
AAPT err(943142208): Found at pixel #1 along left edge.
This is how I resolved it: Open draw9patch tool under your Android Sdk directory
cd /Android/sdk/tools
./draw9patch
Open .9 png and save it again. Hope it helps.
Upvotes: 32
Reputation: 188
For me the problem seems to be that I created the 9 patch myself. I thought it was enough to have a 1 px border on the left and top edges, but you need to make sure that the image has a 1 px border on each edge.
Upvotes: 1
Reputation: 3592
I had the same problem when I migrated a project form Eclipse to Android Studio.
What you need to do is, remove .9 from the image file name and then, open it in draw9patch tool (located in your /sdk/tools directory) and now, click on Show Bad Patches button on the right upper corner.
You should then see the bad pixels and areas marked in red, you need to do some work there until you have no red bad patches. For me, I just marked one pixel on the middle left edge, and one pixel on middle upper edge, and marked almost all of the right edge and bottom edge. click button again and see that you have no bad patches.
Save the file as .9.png and put it back in the res folder of your project. Android Studio should then build your project with no problem for 9 patch iamges.
Upvotes: 8
Reputation: 1199
When the error comes up it opens the image in android studio as well. All I did to fix this was extend any of the patch borders by a single drawn pixel. I re-ran and it worked. Not sure why, but I repeat tested this with several images.
Upvotes: 0
Reputation: 3938
In my case I mistakenly extended the black border into the top left corner. Make sure the corners are transparent.
Upvotes: 5
Reputation: 11002
Just for the record: For me it turned out that this error came from a black border line on the right hand site and bottom side. So I had a black border on every side (top, right, bottom and left). Removing the redundant right and bottom line worked like a charm.
Upvotes: 1
Reputation: 38727
The resource compiler strips 9-patches one-pixel borders away (and presumably stores the information gained from them in a more efficient way outside of the .9.png file). If you've fished these .9.png files out of an .apk, you'll need to add the border back by hand.
Upvotes: 11