9-patch image error in Android

前端 未结 14 1046
野性不改
野性不改 2020-12-04 12:53

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\         


        
相关标签:
14条回答
  • 2020-12-04 13:28

    I have resolved it by changing the stretch scope in Android Studio.

    0 讨论(0)
  • 2020-12-04 13:29

    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.

    0 讨论(0)
  • 2020-12-04 13:31

    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.

    0 讨论(0)
  • 2020-12-04 13:31

    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.

    0 讨论(0)
  • 2020-12-04 13:32

    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.

    0 讨论(0)
  • 2020-12-04 13:33

    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.

    0 讨论(0)
提交回复
热议问题