9 patch image prevent build project android studio - android

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

Related

How to expand vector drawable?

I was trying to expand my shape but only from one side.
What I have:
https://imgur.com/NboRnFw
What I want to have:
https://imgur.com/eTQpA75
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="368dp"
android:height="257dp"
android:viewportWidth="368"
android:viewportHeight="257">
<path
android:pathData="M0,6H348C359.046,6 368,14.954 368,26V243H0V6Z"
android:fillColor="#E7C9FF"/>
</vector>
How can I do this in Android Studio? Is there some kind of image scaling to achieve that? I don't want to change the resource code of this shape.
For something like this, its better yo use 9 patch images. You wouldn't achieve this result any other way since changing width height ratio will make the image distorted.
You can specify the area which expands by giving it 1 pixel order, very easy to set up and there is a built in editor in Android Studio.
Make a PNG from your SVG first, then in Android Studio, right-click the PNG image you'd like to create a NinePatch image from, then click Create 9-patch file.
https://developer.android.com/studio/write/draw9patch
It takes literally a few seconds to create a 9 patch. You can also use this online editor to build a nine patch without Android Studio.
(I was trying to make your drawable into a 9 patch but it had a white background which was causing issue.)

9patch image and Android Studio build failing

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.

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 editor android studio suddenly black

Anyone with experience having the 9 patch editor in AS suddenly start using a black background for images? I have had no problems using it, now suddenly I can't make any edits. The image below should have a transparent background. If I try and drag the stretchable patches nothing changes, it keeps resetting itself, so to speak. Also this change happened in the same session.
Question is old, but I have run into this issue 5 minutes ago. The problem occur when I save custom .png in paint.net and choose option for depth color "auto-detection". But when I saved it with with color depth "32 bit" all ok, and background is transparent.
I have the similar problem, right-click to select "Create 9-Patch file...", the transparent area become black. It only occur in some images after converted by ImageMagick.
Check the image details by pngcheck tool:
xb#dnxb:/tmp$ pngcheck msg_box.png #original image
OK: msg_box.png (2251x967, 32-bit RGB+alpha, non-interlaced, 99.9%).
It becomes palette+trns after converted by ImageMagick:
xb#dnxb:/tmp$ convert msg_box.png -transparent white -trim msg_trim.png
xb#dnxb:/tmp$ pngcheck msg_trim.png
OK: msg_trim.png (394x311, 8-bit palette+trns, non-interlaced, 98.5%).
The solution is prefix the image with png32 to force it outputs RGBA:
xb#dnxb:/tmp$ convert msg_box.png -transparent white -trim png32:msg_trim.png
xb#dnxb:/tmp$ pngcheck msg_trim.png
OK: msg_trim.png (394x311, 32-bit RGB+alpha, non-interlaced, 99.4%).
xb#dnxb:/tmp$
Now when I paste this image in Android Studio and right-click to select "Create 9-Patch file...", then it able to keep transparent instead of black.

Problem while creating 9 patch images

I am creating 9 patch images using draw9patch tool and saving images with extension .9.png but when I am using created 9 patch images in app it is giving error.
But when I downloaded an 9 patch image from net & used in my same app it is working properly.
I am not getting what I am doing wrong .
Please Help
You must be creating the 9-patch wrongly. I had also the same issue . You must be drawing the black patch on one side of image. Try to draw the black patch by dragging your mouse two side of image. I hope you can understand my words...........
Nine-patch images on Android must have transparent 1-pixel edge, and have opaque pixels in left-top border (1 pixel wide) specifying which part of image is stretched, and which do not.
More here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

Categories

Resources