I think I'm finally understanding how the draw9patch tool works, and with that, how .9.png files work as well. Just because it wasn't clearly explained in anything else I saw (well, clearly to me, anyway), I'm going to try to do a quick explanation of how it works.
The first thing to remember about the draw9patch tool is that it's generally for use after you've already edited a .9.png file, and that a .9.png file is built to be stretched. To start editing .9.png files, just decompile the source apk (usually something like framework-res.apk) with the apk manager or apktool.
Open the .9.png file in Photoshop and edit everything except for an area 1 pixel wide around the edges of the image. That area is sacred. There is probably already something there - if so, leave it.
If you want an easy way to make sure it stays clean, just create a new layer, use the "select single row/column" tool in photoshop to select those single pixel borders one at a time. Using the bucket tool, fill in that single pixel border with a solid color as a visual reminder. Keep that layer in place as you edit as a guide, and when you get ready to save the file, make that the active layer, and use the magic wand to select the area inside the border, then invert the selection (so you just have the one pixel border around the outside selected). Go through any other layers you have in the drawing with that selection still selected and delete anything inside the selection. That will keep the area clear on all layers. Once you've done this, delete the layer with the border and save your .9.png.
Once your .9.png file is saved, start the draw9patch tool (usually in android-sdk-windows/tools/draw9patch.bat).
When you fire up the draw9patch tool in the android SDK, you'll see an arrow on the screen. The easiest option is to just drag the .9.png file into the window. It will open it, but it might be hard to see. If that's the case, drag the "Zoom" slider as far to the left as you can until you can see the entire image.
The first thing you'll want to do is activate the buttons that will best show you how your .9.png file will stretch and move. Here's what each button/setting will show you:
Show/Hide bad patches - this will show you areas where it will stretch, but it will probably look bad. Go ahead and make this show bad patches (the button will say "hide bad patches" if you are currently showing bad patches)
Show lock - I honestly don't know. I haven't yet seen this setting work for anything. Leave it unchecked.
Show patches - This will show you where your image is going to stretch. Check it.
Show content - This will show you where things get written/overlayed on your image. Check it.
Zoom - Zooms the image.
Patch Scale - adjusts the preview of how your image will stretch at different scales.
Now, you're probably wondering how .9.png files determine how the image stretches, and where stuff gets written. That's what the 1 pixel border tells it (except for where two borders overlap - that's a dead area). Here's the way it works:
The border on the top of the screen controls the area of the image that stretches left-to-right. Every black pixel you put in this border selects a portion of the drawing that will be repeated when Android needs to stretch the image in the landscape direction.
The border on the left side of the screen controls the area of the image that stretches up-and down. Every black pixel here will set a repeating area as the image stretches in the portrait direction.
The border on the right side of the screen sets how much area in the portrait direction is available to have items drawn inside of it. If you have some text that will be written on your image by Android (a clock, for example), it will check the black pixels on the right side of the screen to determine where it can put them.
The border on the bottom of the screen works in conjucntion with the border on the right side to determine the landscape portion of the area where things can be drawn.
One thing you'll notice with draw9patch is that it will only let you draw in the 1-pixel borders. This makes it generally easier than Photoshop to work with.
To start, just draw a few pixels at the top and left side borders, then look in the preview pane on the right side of the window. That will show you how those areas will repeat. If you adjust the scale, you can see how it will repeat over a greater area. If a patch isn't going to work, it will show up highlighted in a red border. If you need to erase, just hold shift and then click on the pixels you need to get rid of.
Once you have a stretchable area that works for you, put some pixels in the bottom and right borders until you're happy with the area that will accept drawing items. If you look in the window on the right, you'll see a blue area highlighted where that stuff would go. As long as that looks ok to you, you're good to go.
After you've checked everything and it all looks like it will stretch well, you can just use the File-Save command, and it will save a good .9.png file that (should) compile properly.
A quick pointer that I'm discovering: If you have an image that really won't stretch well in any direction, just delete everything two pixels in from each edge, leaving a transparent line just inside the 1-pixel border. Then select those areas as your repeating areas. It may mean your item shrinks on the screen, but it also means it will look the way you intended.
Good info, thanks.
Sent from my SAMSUNG-SGH-I897 using XDA App
Well done!
If I don't have to make an image with customized draw9patch guides, I personally prefer to make my images before adding the 9patch guides. If you have the fully decompiled .png with the 9patch pixels visible, any slight mistake (partial erase, glow/fade/shadow overlap, ect.) can cause an error when you try to compile it.
Check the size of the .9.png you want to edit before it has been decompiled, and open a new photoshop document in that same size. Make your .png. Decompile, then drop your new image on top of the old one and merge the layers (you may need to erase some parts of the original if they are overlapping). If you find yourself repeatedly editing some of the more common .9.png files, it can also help to make a transparent image template that only has the draw9patch guides on it. Make sure it decompiles and compiles properly, and then you can drag and drop it over your new images, merge layers, and you're finished. Obviously, this only works on images that will be the same size and have the exact same draw9patch guides. Those template borders are very useful for porting and minor changes to common .9.pngs.
Thanks, 10ton.
Since writing up that first post, I came across this. It's the xUltimate-draw9patch tool. I know it's been posted before, but this is the super stripped-down version. It has the application and two folders. You dump your decompiled, doctored up .9.png's in the deepest folder of the "originals" folder set, and then run the xUltimate-d9pc tool. It will compile the .9.png files (assuming all is well - it'll give you useful error messages if they're not right) and spit out the finished ones in the deepest folder of the "done" folder set. From there, it's just a matter of sticking them back into the apk's with 7zip.
I personally have found it to be pretty useful when compiling multiple .9.png's at once, instead of using the draw9patch tool or apk manager.
Related
Like many other's i have tried to hop onto the skinning boat after the release of metamorph.
and i think like many others i have problems with those .9.png files. i read stericsons write up on them but i cant make any sense out of it.
therefore i would like to ask from any of you that do understand them: could you make a short video describing the editing of 1 file?
since i'm a visual kind of guy this would 99% sure make me understand it and make me able to continue with my theme.
i would really really apreciate this guys..
you can power up draw9patch and play with it and you will understand it..
few thing you should know
when you load a regular png file(not .9.png) the tool automatically expend the size by 1 pixel each side(up down left right)
then you can edit
the left and top sides represents stretchable area.. you should put there one or two black pixels.. no more!(for each side)
the right and bottom sides are represents the content area.. you can fill it how you like.. but keep it one line for each side
then you need to save it.. when you save it the tool adds a .9 to the end of the file name
the next move is to compile the file with eclipse........
i dont have time to make a vid right this second, but im willing to help you out...first tell me, have you checked out the source code? It has all the .9.png's UNCOMPILED, which means that they still have the guides drawn and you can take a look at certain images to get an idea of how the guies SHOULD be drawn for a certain image.
Brief explanation...The TOP and LEFT sides of the 1px border are where you will draw a single (or double is allowed) guide marker to mark where the image will be stretched. You are allowed up to 2 guides on the top and 2 on the left, but no more.
On the BOTTOM and RIGHT sides of your 1px border you will draw guide markers for the "Content area" of the image. That is to say, if you have a button that will contain text, image, or other content, you draw a line across the bottom edge from one side of the button to the other to center the content in the center of the button. Then the same for the right side to make it centered vertically.
You should check out the source and look at those images in there, that'll help you see what draw9patch does and how certain images should look when they're done.
Then you have to compile the images in eclipse to get them to work right. just start a new Android project and choose "From existing Source", then choose one of the samples that comes with the SDK...i use home.apk. then after you edit the .9.png's with draw9patch, you dump them into a folder (i.e. res/drawable or res/drawable-land) in the project, overwrite whatever images may already be there, and then right click the root of the project in the tree view and go down to "Android Tools" and pick "Export Unsigned package". (it doesnt matter if its signed cuz your just gonna extract it for the images)
This will save an .apk file to your eclipse workspace directory. just copy it to your desktop and extract it to get the freshly compiled .9.png's and inject them into your .apk or update.zip...then sign and flash!
Hope this helps...
-BMFC
ok so the problem for me seems to lie with eclipse, atm i'm stuck on the fact that when i try to open an existing project, i dont have the AndroidManifest.xml and when i extract it from some other theme, it says it cant be parsed. so eehm where exactly should i find a unparsed AndroidManifest.xml or what should be in it?
you already got me a lot further! thanx!
did you try using a different sample application? there are some that throw some errors when i first try to open them as projects but home.apk seems to work fine for me. i tried to figure out why youd be getting that error but i dont seem to get it for any of my samples so maybe its a problem with your SDK? im not sure but here is my AndroidManifest.xml from the home.apk sample, it works for me so it SHOULD work for you. if not you may have a deeper issue going on. anyways just drop the ".txt" from the end of the filename and drop it in [YourSDKdirectory]/platform/Android 1.6/samples/Home/ and then try to open as existing project again. Lemme know if it works...
-BMFC
View attachment AndroidManifest.xml.txt
Is there a way that you can make .9 images on photoshop? Or someway to get around using the 9 tool found in the sdk?
AndroidFiend said:
Is there a way that you can make .9 images on photoshop? Or someway to get around using the 9 tool found in the sdk?
Click to expand...
Click to collapse
yeah, you just give the image a 1px border on all sides and then draw the guides on the border and then save it and compile with eclipse...its the same basic thing, the draw9patch tool just automates most of it for you.
-BMFC
Hey, I'm also one of the people who jumped in the Metamorph bandwagon(not that it's bad), and I'm also having trouble with .9.png's.
In my case, I downloaded an existing Metamorph theme, and I'm basically recoloring some .9's here and there. So, is it possible to just open the .9's in Photoshop, recolor them, then save it as normal? or do I still have to recompile it in Eclipse?
Thanks in advance.
bmfc187 said:
i dont have time to make a vid right this second, but im willing to help you out...first tell me, have you checked out the source code? It has all the .9.png's UNCOMPILED, which means that they still have the guides drawn and you can take a look at certain images to get an idea of how the guies SHOULD be drawn for a certain image.
Brief explanation...The TOP and LEFT sides of the 1px border are where you will draw a single (or double is allowed) guide marker to mark where the image will be stretched. You are allowed up to 2 guides on the top and 2 on the left, but no more.
On the BOTTOM and RIGHT sides of your 1px border you will draw guide markers for the "Content area" of the image. That is to say, if you have a button that will contain text, image, or other content, you draw a line across the bottom edge from one side of the button to the other to center the content in the center of the button. Then the same for the right side to make it centered vertically.
You should check out the source and look at those images in there, that'll help you see what draw9patch does and how certain images should look when they're done.
Then you have to compile the images in eclipse to get them to work right. just start a new Android project and choose "From existing Source", then choose one of the samples that comes with the SDK...i use home.apk. then after you edit the .9.png's with draw9patch, you dump them into a folder (i.e. res/drawable or res/drawable-land) in the project, overwrite whatever images may already be there, and then right click the root of the project in the tree view and go down to "Android Tools" and pick "Export Unsigned package". (it doesnt matter if its signed cuz your just gonna extract it for the images)
This will save an .apk file to your eclipse workspace directory. just copy it to your desktop and extract it to get the freshly compiled .9.png's and inject them into your .apk or update.zip...then sign and flash!
Hope this helps...
-BMFC
Click to expand...
Click to collapse
hey brotherin ..
i didnt have to do that at all. just make sure you have a fresh .png to work with.
)i.e - ballsack.png - wanna stretch it so the sack is in the middle of png.
)do the lines up top and left like stated .. but the guides really arent that important at the bottom.
)next you will than get it to your liking - watch the right side of screen in the example pane, you can see the image shifting - hence you can shift gradients and such with more guide lines behind the first pixel that you mark for guide line. get it?
)than you save the file from the "File" option as a .9.png file.
)and walla its a .9 that can be shfted with the existing metadata that is there.
just dont get too advanced or imsure it wont work to well.i have edited all kinds of them in PSCS4 and than the .9 editor from HTC. Its hard as **** to do. but it pays off. hope this helps.
like bmfc said, get the uncompiled .9.png from the source. makes it so much easier.
then what I do is
open the source .9.png in cs4
marquee tool, and select all content except the guidelines, make it invisible
save that image as ex. guide.png.
take all the images that look the same i.e pressed/selected/default of the same images
open them and the guide.png in photoshop, copy and paste the modified .9.png onto the guide.png, then I save as the original image, repeat as many times as needed,
then when done with that before I compile, I move all of the images with guidelines to a folder ex. guidelines, so that I will have them for future use.
then follow what bmfc said to compile them in eclipse.
check out this video walthrough for working with the .9.png files.
http://www.youtube.com/watch?v=Lf1l9JV9JBw
thanks for the info
the youtube link was a great help
less frustrated....and need improvement but at least getting better and getting the hang of it
the attachment was just for kicks and practice
takumi2k4 said:
Hey, I'm also one of the people who jumped in the Metamorph bandwagon(not that it's bad), and I'm also having trouble with .9.png's.
In my case, I downloaded an existing Metamorph theme, and I'm basically recoloring some .9's here and there. So, is it possible to just open the .9's in Photoshop, recolor them, then save it as normal? or do I still have to recompile it in Eclipse?
Thanks in advance.
Click to expand...
Click to collapse
completely legit. ive been doing it now for a while, works fine. after editing in photoshop, just close the image and click ok when it asks if you want to save the changes.
Hi guys. I took an icon off of a website, and edited it to make the background transparent using paint.net. When i put the icon on my phone it has a black background. I also added another icon from a website that already had a transparent background and that one stayed transparent. any ideas?
the one you created yourself, did you re-save it as a png? if so what version of png did you save it as? 32bit?
wayferer said:
the one you created yourself, did you re-save it as a png? if so what version of png did you save it as? 32bit?
Click to expand...
Click to collapse
they were both already in .png format, but let me check version....
well, I'm not sure where to check that, but if it's the same as bit depth, they are both 32 bit depth (properties/details, bit depth). so that can't be it. or...?
I don't know much on this stuff, just making some shortcuts for some bookmarks. even had to search how to edit the icons. preciate your help.
that's odd. i dont use paint.net (prefer fireworks) but i just download / installed it and went in, made the background transparent (opacity setting in Layers -> Layer Properties) then added a new layer and drew a picture. I then went Save As (choose a location) picked png as my file format and clicked save. I was then shown the Save Config screen where I choose 32-bit and clicked ok and it worked.
Was your process similar?
wayferer said:
that's odd. i dont use paint.net (prefer fireworks) but i just download / installed it and went in, made the background transparent (opacity setting in Layers -> Layer Properties) then added a new layer and drew a picture. I then went Save As (choose a location) picked png as my file format and clicked save. I was then shown the Save Config screen where I choose 32-bit and clicked ok and it worked.
Was your process similar?
Click to expand...
Click to collapse
haha I wish! my process was this.
save file off of website. open file in paint.net. screw around for an hour trying to 'fill' (paint bucket) with transparent 'color'. give up, search for a bit. find that i can just use the magic tool (wand) to select the background area, change tolerance to 25%, edit/cut the selected area and it automatically makes it transparent. select background, make transparent, shrink down to 72 x 72-ish, save file and left on auto detect.
and that was it. the layer stuff confuses me (i understand the concept, but dont know how to work with it) so I didn't mess with layers.
ok, i went in and redid it and its working now. only thing I did differently was when I saved it, instead of letting it autodetect, I chose 32 bit. obviously they're both in 32 bit so I'm not sure what the difference is, but it worked! thanks so much for your help!
It would have been easier if I could just select the shape of the icon and pull it off of the square 'file' that it came as, but I didn't know how to select the image part of the file.
and what's REALLY weird is when I just made the new icon on my phone, i accidentally used the SAME file I was using yesterday instead of the updated version... and it now has a transparent background. WEIRD.
ah yes i hear the auto detect doesn't work as well as one would expect. I'm glad you are sorted now Some advice would if you are going to do more of this in future, acquire a copy of Adobe Fireworks
jirafabo said:
and what's REALLY weird is when I just made the new icon on my phone, i accidentally used the SAME file I was using yesterday instead of the updated version... and it now has a transparent background. WEIRD.
Click to expand...
Click to collapse
there's a ghost
never even heard of adobe fireworks, but you can be sure I'll be making more transparent background icons now! I had acquired a copy of photoshop but it takes up a lot of space and I've never really used it, so paint.net was good enough. I'll check out fireworks and maybe even look for some free online intro lessons.
i prefer it over photoshop, even for my day job let me know if you ever need a hand
Big question. When you rotate the phone, the status bar background (in themes like Darkness, with a design) gets messed up because it's shaped for our screen and not a small piece that gets tiled like the original. Can you make a landscape version of the background? I noticed in TouchWiz30Launcher.apk there is a homescreen_icon_bg.png and homescreen_icon_bg_h.png the latter being for a horizontal orientation of the launcher. Can we apply this concept to a custom made portrait AND landscape drawer background in twframework-res.apk? I would really like to know if it is possible, but am not asking for the creation of the background. I can make my own, but I need to know how to make it work.
I think you have to create a layout-land and layout-port folder and put something in there. Hopefully someone else will chime in.
A simpler idea might be to modify status_bar_expanded.xml to have multiple images for the background and bottom bar, like 3 where the center is fixed and the outer 2 are tiled matched up to look seamless of course. Or just allow certain parts to be stretched and some not with draw9patch.
CuriousTech said:
I think you have to create a layout-land and layout-port folder and put something in there. Hopefully someone else will chime in.
A simpler idea might be to modify status_bar_expanded.xml to have multiple images for the background and bottom bar, like 3 where the center is fixed and the outer 2 are tiled matched up to look seamless of course. Or just allow certain parts to be stretched and some not with draw9patch.
Click to expand...
Click to collapse
Thanks a lot for your post, I looked into status_bar_expanded but couldn't find anything applicable. Looked at status_bar.xml and it contains all the info on status_bar_background in the vertical position. How would you put it all into horizontal? Would you have to edit the existing xml or make a new one in layout-land? Could I just copy it into layout-land and edit in some new filenames and stuff?
EDIT: You know how to signify a file it says @drawable/statusbar_background? Does this actually refer to status_bar_background.9.png? And how would you signify a drawlable-land destination? @drawable-land/statusbar_background?
That's mostly what I don't understand yet. In framework-res there are 3 folders:
layout
layout-land
layout-port
icon_menu_layout.xml is in land and port and not in just layout. I think because layout is default for both, and land or port is used for those modes if the file doesn't exist in layout. Just like an xml in drawable can replace an image if the same name is used. But I think there's more to it than that. I tried creating a layout-land and layout-port and moved status_bar_expanded.xml to both and it looked normal both ways. I would think that layout-land would automatically use the drawable-land images too. Something else is missing.
EDIT: Oh yes @drawable/statusbar_background is the png in drawable-hdpi, unless there's actually a drawable/statusbar_background.xml which would make it use that instead. I just don't know where drawable-land-hdpi fits in.
Inside the XML there is a "vertical" and "horizontal" section, you'd have to change that too. I have changed it and will try it tonight in my framework. I just don't understand the references it makes too well...
I've been trying to find a simple reference, but I guess most of it's here:
http://developer.android.com/guide/topics/ui/layout-objects.html
Or around that area of the docs. The vertical/horizontal I think is the alignment of objects in a group. I don't think it has to do with land/port.
This looks interesting too. I just found it. It looks like a way to view layouts on the computer.
http://developer.android.com/guide/developing/tools/hierarchy-viewer.html
CuriousTech said:
I've been trying to find a simple reference, but I guess most of it's here:
http://developer.android.com/guide/topics/ui/layout-objects.html
Or around that area of the docs. The vertical/horizontal I think is the alignment of objects in a group. I don't think it has to do with land/port.
This looks interesting too. I just found it. It looks like a way to view layouts on the computer.
http://developer.android.com/guide/developing/tools/hierarchy-viewer.html
Click to expand...
Click to collapse
I honestly don't know what that stuff means with a headache, so I can't understand what the links refer to, sorry
It's all really disorganized or I'm just used to Microsoft docs. The xml corelates with the android classes for coding java. So xml is used sort of like html tables where everything is nested so you can have rows or collumns of buttons (horiz/vert) or menus or whatever, but the elements used are all the members of the android class. It's just so hard to find the meaning of each one.
CuriousTech said:
It's all really disorganized or I'm just used to Microsoft docs. The xml corelates with the android classes for coding java. So xml is used sort of like html tables where everything is nested so you can have rows or collumns of buttons (horiz/vert) or menus or whatever, but the elements used are all the members of the android class. It's just so hard to find the meaning of each one.
Click to expand...
Click to collapse
Crap 10char
I downloaded an icon set (IDroid) from deviant art and the developer gave his PSD file so we could make our own. I want to make a Tumblr icon using his settings, any way I could go about going that? I use Adobe Photoshop btw.
Copy and paste the image you want to use in the clipping mask then size it down if you need to then nudge it to your preferred center.
Or you can draw one using the pen tool. And fill your paths with disired gradients and overlays etc...
save as Web or device
I did that but when I saved it aand tried to use it as an launcher icon on my phone it had a white background around the edges. How do I get that cut that off? And also save the icon as 72 x 72 to fit the icon sizes like on my phone. Thx in advance.
You saved as png right?
If so maybe you had a "background" layer still selected when you saved it. That happens to me sometimes and i don't realize it till its on my phone..pisses me off.
Anyhow try it again and let me know.
Im trying to resize a set of icons in photoshop.
They are circular, transparent background PNG files.
As is, they are clear & smooth.
Upon import they are automatically distorted, beyond belief.
At this point there has been no editing, i have simply opened the file in photoshop.
Im not sure if its relevant but they are opening as index, locked.
Its not a universal issue, other images open fine.
Any suggestions would be welcome.
Also any other advice on what im trying to accomplish;
- resize canvas up (to enlarge transparent background)
- resize image down to original size (to give the effect of a smaller icon)
Im aiming to batch convert a group, ive already defined the actions in photoshop so if i can get around the issue within photoshop that would be my first preference.
Cheers.