How to edit .9.pngs

Search This thread

cloverdale

Senior Member
Feb 9, 2009
1,596
147
Eugene, OR
www.jbthemes.com
If you have tried to edit .9.pngs in the res/drawable folders, then you know the reason for this thread. If you have not, the idea is that .9.pngs do not have a static boundary. Instead the boundary is given by a continuous mapping

b:[0,1) --> R^2

wherein the mapping is defined by guides which cannot be seen in regular graphical editing programs. This will give the basic idea, along with an example of how this works.

What you will need:

1.) draw9patch (found in /tools of the Android SDK: http://developer.android.com/sdk/index.html)

2.) gimp (or equivalent graphics software)

3.) Java 1.6 (not 1.5)

4.) Eclipse 3.5 with ADT 0.95 (Setup to compile android 1.6. Instructions: http://developer.android.com/guide/developing/eclipse-adt.html) It is assumed you are comfortable with eclipse. There are many threads on setting up eclipse, along with the linked instructions, so try and keep eclipse questions in this thread to a minimum.


Step-By-Step

1.) Find your desired file to edit, which from here on will be referred to graphic.9.png, and rename to graphic.png.

Reason: We will open the file in gimp (or an alternative .png editing app) which will not recognize the .9.png, and will open as .png. This will cause the invisible guides to open as filled in, and thus the guides will need to be redefined before we save. If we open a .9.png extension in draw9patch, it will assume the guides exist, which of course will not if we edit in another application, and thus not be added. By changing the extension to only .png, when opening in draw9patch, the guides will be re-added.

2.) Open graphic.png in gimp and do your desired editing.

3.) In your computer terminal enter draw9patch (assuming you added /tools to your path, otherwise in the terminal navigate to /tools in the AndroidSDK and enter draw9patch). Possible Issue: If draw9patch comes up blank with no menu, you do not have Java 1.6 set as default. Fix this via sudo update-java-alternatives -s java-6-sun in the terminal (or something similar for your system).

4.) Drag and drop graphic.png into the resulting draw9patch window. What you will now see is your image, along with transparent lines which will be where your guides are defined. One should read this http://developer.android.com/guide/developing/tools/draw9patch.html, though it is not that clear. Draw9patch allows you to add/remove black squares which define the actual guides. I will admit that this is one part of the process that I am still not completely comfortable with, and sometimes requires a little trial and error. Here is what I have figured out:

(i) You will want to draw a solid black line along the bottom and right edges of your image. This designates the boundary which results from the region which is stretched.

(ii) You will now add black squares to the top and left sides. These designate the solid part of the region that will be stretched (as opposed to staying transparent).

As I stated before, this part is a little confusing, but with some trial and error, anyone can figure it out. See my following example to witness the guides being used.

5.) After the guides are defined, save the file in draw9patch. This will automatically append .9 to the filename, and give an actual .9.png file that has been edited (now called graphic.9.png). We are not quite done though, because as is, the guides will not be recognized by the android OS. The images need to be compiled in eclipse as part of an apk.

6.) Open Eclipse and create a new project. You can name it anything you like, and you can just uncheck defining an activity. This project will automatically generate a res/drawable (or res/drawable-hdpi) folder, in which you will drag and drop graphic.9.png. From here, right click on your project, choose "Android Tools", and "export unsigned android application".

7.) In step 6 an .apk was created (I choose to save to desktop), extract the files, and open the folder in which graphic.9.png was placed. This is your newly edited, ready to use .9.png. Enjoy and have fun theming.


Example: How to change the outline of the inner squares on the power widget from orange to white.

1.) I take the file appwidget_inner_focus_c.9.png (found in Settings/res/drawable) and rename to appwidget_inner_focus_c.png.

2.) Open in gimp (figure_1) and change color to white (figure_2).

3.) Open draw9patch

4.) Drop appwidget_inner_focus_c.png into draw9patch (figure_3) and define guides (figure_4). In fig.3 the purple color is showing where the patch will be applied (i.e. where the stretching will occur). After I define the guides, (fig.4) note the vertical and horizontal green lines with signify the only color stretching will be along the boundary itself.

5. Save the image as appwidget_inner_focus_c.9.png (anywhere you like).

6. Drag and drop the file into the res/drawable-hdpi folder in your project folder (navigate to through regular computer file browser). Note that it is in the correct folder (fig.5). Right click on the project (in my case Aaron) and choose Android Tools, the export unsigned android application. Aaron.apk now appear on my Desktop (I chose desktop to export to), which I extract my appwidget_inner_focus_c.9.png from.

7. I am now done. :)
 

Attachments

  • figure_1.jpg
    figure_1.jpg
    10.6 KB · Views: 5,415
  • figure_2.jpg
    figure_2.jpg
    10.1 KB · Views: 4,257
  • figure_3.png
    figure_3.png
    15.2 KB · Views: 4,164
  • figure_4.png
    figure_4.png
    18.7 KB · Views: 3,859
  • figure_5.jpg
    figure_5.jpg
    11 KB · Views: 3,302

jairomeo

Senior Member
Mar 22, 2009
1,519
97
727
www.designrifts.com
You don't actually need to use the draw9 tool. You can use your favorite photo editing software, whether it be Photoshop, Paint.net or GIMP and you can just add a 1px wide black border where needed and it works just the same.

Of course if you download the source from cyan's github then you can edit them from there, the source code is unprocessed so it still has the 1px black border around it. To me this is the easiest way to do it, then you don't have to worry about where you place the lines, they are already there.

After you edit, then you still need to do the above in eclipse.
 
Last edited:

cloverdale

Senior Member
Feb 9, 2009
1,596
147
Eugene, OR
www.jbthemes.com
You don't actually need to use the draw9 tool. You can use your favorite photo editing software, whether it be Photoshop, Paint.net or GIMP and you can just add a 1px wide black border where needed and it works just the same.

Of course if you download the source from cyan's github then you can edit them from there, the source code is unprocessed so it still has the 1px black border around it. To me this is the easiest way to do it, then you don't have to worry about where you place the lines, they are already there.

After you edit, then you still need to do the above in eclipse.

Wow, that is much easier, thank you.
 

athanos

Senior Member
Apr 4, 2010
510
29
Ok. So, everything was going great, but I ran into a problem. I am able to edit my .9.png's just fine. However, when I "export unsigned android application" in Eclipse I get an error that the package does not exist. Looking closer I see that one file in the package explorer has a little sqaure 'x' by it. If I delete that file it works perfectly, but I want that .9.png to be in there. Any clues on why this would happen? Any help would be greatly appreciated. Thanks for the great tutorial by the way. After you edit so many .9.png's you get a little used to it and it's really easy.
 

AnderWeb

Senior Member
Jan 27, 2010
494
9
Ok. So, everything was going great, but I ran into a problem. I am able to edit my .9.png's just fine. However, when I "export unsigned android application" in Eclipse I get an error that the package does not exist. Looking closer I see that one file in the package explorer has a little sqaure 'x' by it. If I delete that file it works perfectly, but I want that .9.png to be in there. Any clues on why this would happen? Any help would be greatly appreciated. Thanks for the great tutorial by the way. After you edit so many .9.png's you get a little used to it and it's really easy.

Thats usually caused by a bad 9patch. The 1px marquee around the real image can only contain full transparent pixels our full opaque pixels (the patch guides).
Open your png with gimp/photoshop/whatever and look into that area to see if there's something painted.
 

jairomeo

Senior Member
Mar 22, 2009
1,519
97
727
www.designrifts.com
Ok. So, everything was going great, but I ran into a problem. I am able to edit my .9.png's just fine. However, when I "export unsigned android application" in Eclipse I get an error that the package does not exist. Looking closer I see that one file in the package explorer has a little sqaure 'x' by it. If I delete that file it works perfectly, but I want that .9.png to be in there. Any clues on why this would happen? Any help would be greatly appreciated. Thanks for the great tutorial by the way. After you edit so many .9.png's you get a little used to it and it's really easy.

If you look at the errors it will tell you which file is bad and even if it's the top, bottom or sides that have a bad pixel in the border.
 

mr.megi

Senior Member
Jun 9, 2010
753
858
if someone want to help me how to do this on msn pleas PM me , im noob on eclipse :(
 
D

Deleted member 2500726

Guest
Why is the Eclipse part needed? I have no problem compiling my apk without doing that.
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
This thread is quite old. Apktool (my signature) is able to properly decode 9.png files - it adds borders where they should really be. Don't waste your time on adding them by hand.
 

Mobzter

Senior Member
May 9, 2010
1,345
209
can you be more precisly?
how to handle for example with the genie.widget?
there are 3 9.pngs included which i want to edit....


you would do each 1 as presented earlier.
copy all 3 to main workspace used for eclipse and export unsigned.
then you need to replace the .pngs within the widget.
if its not a system ul most likely have to sign the app aswel.
may have to look around for how to do this
 

dabicho

Member
Jan 13, 2011
9
0
Someone correct me if I am wrong.
But I came upon this piece:
osdir.com/ml/Android-Developers/2011-01/msg00529.html

The format is standard PNG. Build tools add a custom chunk containing patch data.

So you still need to patch the .9.png and that is done as one part of the build process. (step 6)
Is there a more direct way of doing it?
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
So you still need to patch the .9.png and that is done as one part of the build process. (step 6)
Is there a more direct way of doing it?

No, aapt is only one tool, which does borders -> 9patch chunk conversion and it always works on a whole project, not single PNG. But it should be quite easy to create such tool - I've already done 9patch -> borders converter in apktool.
 

Juevani

Senior Member
Dec 7, 2008
100
2
Oslo
3.) In your computer terminal enter draw9patch (assuming you added /tools to your path, otherwise in the terminal navigate to /tools in the AndroidSDK and enter draw9patch). Possible Issue: If draw9patch comes up blank with no menu, you do not have Java 1.6 set as default. Fix this via sudo update-java-alternatives -s java-6-sun in the terminal (or something similar for your system).

what if it doesnt come up at all?????

I have everything installed the way it should :

Android SDK (updated)
Eclipse
ADT Plugin
Java SDK 1.6

Here is the message that I get on my terminal (using mac)

Code:
imad-zianis-macbook-2:tools Juevani$ ./draw9patch
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdesktop/swingworker/SwingWorker
	at com.android.draw9patch.Application$1.run(Application.java:48)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
imad-zianis-macbook-2:tools Juevani$
 

johnny quest

Senior Member
Jul 2, 2010
1,241
253
Port Saint Lucie
Ok, I just can't figure this out. I am going insane trying to figure this out. this is what I got so far:
I've installed the Eclipse, SDK, java, ADT etc....
I managed to modd my images with photoshop and put it through Draw9patch and managed to save my images to the folder of the app I was modifying. I opened up Eclipse and did the steps of: File\New\android project\ create project from existing source. and the part where you should use the default path for the directory. I can't seem to get to the end where I can pick "finish" to move on to the editing.
I did something different and managed to get the 9 pngs normal wthout stripes or marks and into a Res folder.
Ok, the part where you have to Export it is the sticky part. Can you please break down that section a bit more detailed. I got it to Unsigned App Package and I put the apk file on my phone all of a sudden my app was gone on the phone....Ok I modded the calculator with my images and can't seem to get installed.
 

britoso

Senior Member
Jan 13, 2010
2,794
302
Orlando
Ok, I just can't figure this out. I am going insane trying to figure this out. this is what I got so far:
I've installed the Eclipse, SDK, java, ADT etc....
I managed to modd my images with photoshop and put it through Draw9patch and managed to save my images to the folder of the app I was modifying. I opened up Eclipse and did the steps of: File\New\android project\ create project from existing source. and the part where you should use the default path for the directory. I can't seem to get to the end where I can pick "finish" to move on to the editing.
I did something different and managed to get the 9 pngs normal wthout stripes or marks and into a Res folder.
Ok, the part where you have to Export it is the sticky part. Can you please break down that section a bit more detailed. I got it to Unsigned App Package and I put the apk file on my phone all of a sudden my app was gone on the phone....Ok I modded the calculator with my images and can't seem to get installed.
I do it this way:
1) get the .9.png files from the apk
2) redo the patches using draw9patch, save as .9.png
3) "compile" (process) the edited .9.png files with xeudoxus's xUltimate Draw9Patch Compiler. get it from here
4) put the processed .9.png files back in the apk

The compiler removes the 1 pixel border defining the patches that are stretchable and puts that info in the png as metadata (not 100% sure where)
 
  • Like
Reactions: johnny quest

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    If you have tried to edit .9.pngs in the res/drawable folders, then you know the reason for this thread. If you have not, the idea is that .9.pngs do not have a static boundary. Instead the boundary is given by a continuous mapping

    b:[0,1) --> R^2

    wherein the mapping is defined by guides which cannot be seen in regular graphical editing programs. This will give the basic idea, along with an example of how this works.

    What you will need:

    1.) draw9patch (found in /tools of the Android SDK: http://developer.android.com/sdk/index.html)

    2.) gimp (or equivalent graphics software)

    3.) Java 1.6 (not 1.5)

    4.) Eclipse 3.5 with ADT 0.95 (Setup to compile android 1.6. Instructions: http://developer.android.com/guide/developing/eclipse-adt.html) It is assumed you are comfortable with eclipse. There are many threads on setting up eclipse, along with the linked instructions, so try and keep eclipse questions in this thread to a minimum.


    Step-By-Step

    1.) Find your desired file to edit, which from here on will be referred to graphic.9.png, and rename to graphic.png.

    Reason: We will open the file in gimp (or an alternative .png editing app) which will not recognize the .9.png, and will open as .png. This will cause the invisible guides to open as filled in, and thus the guides will need to be redefined before we save. If we open a .9.png extension in draw9patch, it will assume the guides exist, which of course will not if we edit in another application, and thus not be added. By changing the extension to only .png, when opening in draw9patch, the guides will be re-added.

    2.) Open graphic.png in gimp and do your desired editing.

    3.) In your computer terminal enter draw9patch (assuming you added /tools to your path, otherwise in the terminal navigate to /tools in the AndroidSDK and enter draw9patch). Possible Issue: If draw9patch comes up blank with no menu, you do not have Java 1.6 set as default. Fix this via sudo update-java-alternatives -s java-6-sun in the terminal (or something similar for your system).

    4.) Drag and drop graphic.png into the resulting draw9patch window. What you will now see is your image, along with transparent lines which will be where your guides are defined. One should read this http://developer.android.com/guide/developing/tools/draw9patch.html, though it is not that clear. Draw9patch allows you to add/remove black squares which define the actual guides. I will admit that this is one part of the process that I am still not completely comfortable with, and sometimes requires a little trial and error. Here is what I have figured out:

    (i) You will want to draw a solid black line along the bottom and right edges of your image. This designates the boundary which results from the region which is stretched.

    (ii) You will now add black squares to the top and left sides. These designate the solid part of the region that will be stretched (as opposed to staying transparent).

    As I stated before, this part is a little confusing, but with some trial and error, anyone can figure it out. See my following example to witness the guides being used.

    5.) After the guides are defined, save the file in draw9patch. This will automatically append .9 to the filename, and give an actual .9.png file that has been edited (now called graphic.9.png). We are not quite done though, because as is, the guides will not be recognized by the android OS. The images need to be compiled in eclipse as part of an apk.

    6.) Open Eclipse and create a new project. You can name it anything you like, and you can just uncheck defining an activity. This project will automatically generate a res/drawable (or res/drawable-hdpi) folder, in which you will drag and drop graphic.9.png. From here, right click on your project, choose "Android Tools", and "export unsigned android application".

    7.) In step 6 an .apk was created (I choose to save to desktop), extract the files, and open the folder in which graphic.9.png was placed. This is your newly edited, ready to use .9.png. Enjoy and have fun theming.


    Example: How to change the outline of the inner squares on the power widget from orange to white.

    1.) I take the file appwidget_inner_focus_c.9.png (found in Settings/res/drawable) and rename to appwidget_inner_focus_c.png.

    2.) Open in gimp (figure_1) and change color to white (figure_2).

    3.) Open draw9patch

    4.) Drop appwidget_inner_focus_c.png into draw9patch (figure_3) and define guides (figure_4). In fig.3 the purple color is showing where the patch will be applied (i.e. where the stretching will occur). After I define the guides, (fig.4) note the vertical and horizontal green lines with signify the only color stretching will be along the boundary itself.

    5. Save the image as appwidget_inner_focus_c.9.png (anywhere you like).

    6. Drag and drop the file into the res/drawable-hdpi folder in your project folder (navigate to through regular computer file browser). Note that it is in the correct folder (fig.5). Right click on the project (in my case Aaron) and choose Android Tools, the export unsigned android application. Aaron.apk now appear on my Desktop (I chose desktop to export to), which I extract my appwidget_inner_focus_c.9.png from.

    7. I am now done. :)
    1
    Ok, I just can't figure this out. I am going insane trying to figure this out. this is what I got so far:
    I've installed the Eclipse, SDK, java, ADT etc....
    I managed to modd my images with photoshop and put it through Draw9patch and managed to save my images to the folder of the app I was modifying. I opened up Eclipse and did the steps of: File\New\android project\ create project from existing source. and the part where you should use the default path for the directory. I can't seem to get to the end where I can pick "finish" to move on to the editing.
    I did something different and managed to get the 9 pngs normal wthout stripes or marks and into a Res folder.
    Ok, the part where you have to Export it is the sticky part. Can you please break down that section a bit more detailed. I got it to Unsigned App Package and I put the apk file on my phone all of a sudden my app was gone on the phone....Ok I modded the calculator with my images and can't seem to get installed.
    I do it this way:
    1) get the .9.png files from the apk
    2) redo the patches using draw9patch, save as .9.png
    3) "compile" (process) the edited .9.png files with xeudoxus's xUltimate Draw9Patch Compiler. get it from here
    4) put the processed .9.png files back in the apk

    The compiler removes the 1 pixel border defining the patches that are stretchable and puts that info in the png as metadata (not 100% sure where)
    1
    I do it this way:
    1) get the .9.png files from the apk
    2) redo the patches using draw9patch, save as .9.png
    3) "compile" (process) the edited .9.png files with xeudoxus's xUltimate Draw9Patch Compiler. get it from here
    4) put the processed .9.png files back in the apk

    The compiler removes the 1 pixel border defining the patches that are stretchable and puts that info in the png as metadata (not 100% sure where)

    Ok, thanks I will do that and hopefully it works. Its a nongoing battle trying to get this right. I had to delete all my java, eclipse, sdk and reinstall them. But now, my avabox(signing apps back to apk) isn't working since I did all of this. its saying "c:\program files (x86)\java\jre6\bin\msvcr71.dll" but I have that file in my folder I don't know why its saying that.
    or how would I sign my apps back? thanks again
    1
    Is there any way to bring back the patch lines of one .9.png? I need to see the original patch lines for reference so that I can create a new .9.png that match the apk.

    Just decompile that apk again..thats the only way that I know of.. :good:
    1
    Is there any way to bring back the patch lines of one .9.png? I need to see the original patch lines for reference so that I can create a new .9.png that match the apk.

    You can use "9 Patch Editor" for Android (I can't post a link since I'm a newb).
    It can load compiled .9.png files (that you have extracted from an apk) and also save compiled .9.png files to put back into the apk file.

    Disclaimer: I wrote this app. Since it answers your question I can hopefully get away with this plug.