9patch image and Android Studio build failing - android

I have an interesting issue, and I dont know how to handle it.
So, until now everything was fine, I was able to build my project. I just replaced an image with it`s 9patch version in three different sizes(mdpi, hdpi, xhdpi).
tw.setBackgroundResource(R.drawable.tag_rotate)
This is the line, where the building failing. It`s interesing, because the studio is able to show me the image on the left, and it is NOT marked as red. But the build is failing with the following message:
Error:(196, 52) error: cannot find symbol variable tag_rotate
UPDATE:
if I remove the image from the code, and replace with a normal image, it works ! Im using the default 9patcher provided by SDK

What kind of nine-patch generator do you use?
I recomend you to use this generator.
I tried to use standart android 9patch generator, which delivered with android SDK, and I had the problems with it.

Check if there is a line on your imports that says import android.R;.
If there is,Delete the import and it should be fine.

The Draw 9-patch tool is a WYSIWYG editor that allows you to create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. Selected parts of the image are scaled horizontally or vertically based indicators drawn within the image.
http://developer.android.com/tools/help/draw9patch.html
Nine-patch generator
https://android-ui-utils.googlecode.com/hg-history/9472134d092f3375aa9cf767d6a4b2eca561c0ba/asset-studio/dist/nine-patches.html

If you are make online generator tools then Don't use the any special character for image name

The 9 patch tool in android studio is automatically generating bad patches.
You need to repatch till the red bad patches go away and the error should be fixed. To see bad patches just select the Show bad patches checkbox.

Related

Android Studio doesn't recognize 9patch generated images

I generated 9patch images from Simple 9 patch generator available free on the internet for the splash screen. When I write android:background="#drawable/splash.9", it doesn't recognize the image.
Plus , when I select Android from the drop down menu on left top side , I don't see the images I put in different drawable folders.
No need to add the .9 suffix. It's just there to tell the build environment that this is a 9patch. Link to documentation.
android:background="#drawable/splash"
should be enough

Error:Must have one-pixel frame that is either transparent or white in Android Studio

I have just imported a project from eclipse to Android studio. Almost for every second image , android studio is giving the following error.
Error:Must have one-pixel frame that is either transparent or white.
I am trying to edit my images for last few hours, but couldn't do it. Can anyone guide me whats the best solution for it.
Why its in only Android Studio why not in Eclipse.
This is shown because you're trying to edit 9-Patch images that don't have the appropriate 1-pixel border.
Android uses an image format called 9-Patch which allows you to define stretchable areas in an image (you can read more about it here). To fix your problem, either add an outer 1-pixel thick transparent frame to your png images or simply rename them from .9.png files to .png files

9 patch image prevent build project android studio

I am moving to Gradle build . but i have this error for a lot of 9-patch images .
Note the drawable is auto generated by http://android-holo-colors.com
but they are old.
I am using android studio 0.5.1
and my build tool version is 19.0.3
this is the error
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/19.0.3/aapt s -i /Users/Ed/Desktop/TestAndroid/app/src/main/res/drawable-mdpi/spinner_default_holo_dark.9.png -o /Users/Ed/Desktop/TestAndroid/app/build/res/all/debug/drawable-mdpi/spinner_default_holo_dark.9.png
Error Code:
42
Output:
ERROR: 9-patch image /Users/Ed/Desktop/TestAndroid/app/src/main/res/drawable-mdpi/spinner_default_holo_dark.9.png malformed.
Frame pixels must be either solid or transparent (not intermediate alphas).
Found at pixel #3 along top edge.
/Users/Ed/Desktop/TestAndroid/app/src/main/res/drawable-hdpi/cab_background_bottom_test.9.png
Error:Ticks in transparent frame must be black or red. - ERROR: 9-patch image /Users/Ed/Desktop/TestAndroid/app/src/main/res/drawable-mdpi/spinner_default_holo_dark.9.png malformed.
Anyone faced the same problem.
Have you tried following the suggestions in the error log?
I.e. take a look at the 3rd (possibly 4th if it treats it as zero indexed?) Pixel along the top row in an image editor:
Is the pixel red or black (#FF0000 or #000000)?
Does it have an alpha value of 255 or 0?
If the answer is "no", then I guess that's your problem. This will then obviously also need to be applied to all other marker pixels around the edge of the images.
I'd add this as a comment, but don't have enough rep - sorry.
I saw a solution in other feed and the way to fix this issue is to use draw9patch tool to open the image and save it directly. I use this way to solve this issue.
About "draw9patch", you can use that tool in the tools directory of the Android sdk folder or use it directly by clicking the image within the Android Studio, it uses draw9patch as well.
My two cents,
I used photoshop to create my ninepatch and came across this error.
I had used the brush tool in brush mode with the black color to paint the border pixels (content and stretch)
The problem with the brush is that it also colors contiguous pixels with just a tiny amount of very transparent black so that you can't see it. Using the eraser in 1px crayon mode on all the pixel that should have been transparent worked for me.
When working on a nine patch in photoshop always use the brush tool in crayon mode

Issue while using 9 patch

I have an app, that to chatting. I need to create bubbles. I did it with nine-Patch image but it was not useful because I need little triangle on right (left) of the bubble and when nine-Patch stretches the image the triangle also gets stretched. This is the problem.
Can I Draw background of Layout with canvas or etc. ?
Try this ones
download it and do not forget to rename it with image1.9.png
This may not working give me your mail id i will mail you
Also, check this one and rename it as .9.png
It was created using the draw9patch tool located in sdk\tools folder.

How to create nine-patch and use it in my App?

I want to create a nine-patch image and use that in my App but I don't know how to create it?
I've searched through the Android source code on the Web and I can't seem to find any examples of this. I need a tutorial so that I can understand the process.
I have searched the best and the simplest answer to make 9-patch image. Now to make the 9 patch image is the easiest task.
From HERE you can make a 9-patch image for all the resolutions - XHDPI,HDPI,MDPI,LDPI in just one click.
Let me know if you have any queries, and do upvote it, if it was helpful to you.
I just found that awesome alternative 9patch editor (by Mikle Garin) and I think it 1000% better than standard one built in sdk:
Editor JAR download link
Editor source code
Editor official page
There's a tool included in the android sdk to create and test nine patch images:
http://developer.android.com/guide/developing/tools/draw9patch.html
You can also create a nine patch file using every gfx package out there ( photoshop, paint.net, ... ) using the creation guideline here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
I've created a tool that allows automatically create 9-patch images from regular PNG images for simple cases where stretchable areas are 1 pixel wide. Here's sample input and output (showed at 400%):
Project page on github
A NinePatch image is a standard PNG image created with Photoshop, Illustrator, Paint... etc.
To add a NinePatch rule to it, just drag/drop it on the draw9patch.bat tool in your Android SDK directory.
IF you don't use the draw9patch.bat tool, you must include an extra 1px transparent border to draw the NinePatch rules with a 1px black (#000000) pencil size before you save it.
Important!!! Save the image with the extension myimage.9.png as a transparent PNG-8/PNG-24.
Image: Explanation of NinePatch graphic rules
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
Although android provides the tool for ninepatch images .Open terminal and go to android sdk -tools path and type ./draw9patch. But this is the best link you can make for all density in just one click.

Categories

Resources