Please help me transform two images into 9-patch - android

The designer has given me two PNG images and they are supposed to be the background for all the buttons of my app. I am not being able to transform then into 9-patch image. It seems like that one image has too much details to be a 9-patch, stretching it would make it lose the details.
Can you guys take a look and let me know what you think?
http://img211.imageshack.us/img211/1965/background1p.png
http://img845.imageshack.us/img845/676/background2a.png
Many thanks,
Felipe

//repeatimage.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/tileimage"
android:tileMode="repeat"
android:dither="true" >
</bitmap>
and set this image in your layout background as
android:background="#drawable/repeatimage"
//slice your image into small pieces

Try using this tool . It's a simple 9-patch generator that can be of use to you.

For both your questions:
1: I use images with shadows a lot and you can certainly convert them into a 9-patch image. I am not sure how I can explain the actual steps involved in creating this. Perhaps an example will help you work that bit out.
2: For an image with a pattern in it, a 9-patch of it as #Padma Kumar pointed out, will still distort your image. To fix that, you can follow the link attached. It is a nice tutorial on how to use tiled patterns as backgrounds. http://androidforbeginners.blogspot.in/2010/06/how-to-tile-background-image-in-android.html
A side note: The draw9patch can be quite an intimidating tool. Until you get the hang of it, you could consider using this website here: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html. It however, works only in Google Chrome.

Maybe you should check this tutorial: http://www.thesecretpie.com/2010/07/creating-custom-fancy-buttons-in.html
It explains how 9-patch actually works and how to use drow9patch tool which comes with Android SDK. It was really useful for me.
And for the shadows, you just need to save image with transparent background (of course) and with a little free space between shadow and edge of an image which you will use to draw lines for 9-patch

Related

Making a certain color transparent on an image

I have an image that is circular and I want to make the other junk in the image to be transparent. I've spent the last hour looking around and I can't seem to figure out how this is done for android. Any help is greatly appreciated!
I haven't worked with Android but on iOS pngs weren't loading for me when I made them in photoshop but when I made them in flash all of a sudden they would work! Try that first :)
Anyways, you want to google something along the line of "pixel arrays android code" you can create an array of each pixel, find an individual color, then make it transparent...
But I really think this is just a GIMP issue and you don't need to go through all of that hassle.
what i can understand from your uncleared words is that you want to display transparent image of a normal image you have . so i would suggest don't do it through programming . create a transparent image through any image editor tool and use it .
if image is dynamic that you cant go in this way so use Matrix and setAlpha . search over net for both the terms

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.

android transparent picture

do you know how to make a certain part of a picture (jpg) semitransparent, like in the attached image?
Just use a PNG image instead. Problem solved :)
JPEG doesn't support transparency. Can you use a 32-bit PNG instead?
If you have an existing image that you want to apply some transparency pattern to, you will need to create a Bitmap object in code, draw your image, then set some flags to allow you to draw the transparency levels over it, a bit like a Photoshop layer mask. I did a search for Android alpha masking, and found this blog post.
Err - I may be utterly confused here, but why not just use setAlpha(int alpha) on the inflated ImageView?
That seems to work fine on a .jpg for me.
Or is it only part of the image that should be transparent? Hard to see the 'sample image'.

Tiled drawable sometimes stretches

I have a ListView whose items have a tiled background. To accomplish this, I use the following drawable xml:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/tile"
android:tileMode="repeat" />
Usually, this works. Sometimes, however, the src drawable isn't tiled, but stretched to fill the entire list item. (I've got several different tiles like this, and I use them mixed in one ListView. If there is stretching instead of tiling, it's never been in all of them at once, for what that's worth.)
I also tried to add android:dither="true" to that xml, since I read somewhere that without it there might be bugs. That didn't change anything.
Has anyone had the same problem? How did you fix it?
I also got bitten by this problem. Very hard to diagnose, even harder to find similar reports and usable solutions.
"Tapas" on the freenode #android-dev irc channel came with the following utility method:
public static void fixBackgroundRepeat(View view) {
Drawable bg = view.getBackground();
if (bg != null) {
if (bg instanceof BitmapDrawable) {
BitmapDrawable bmp = (BitmapDrawable) bg;
bmp.mutate(); // make sure that we aren't sharing state anymore
bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
}
}
}
Apply it to all Views that have a tiled background set (e.g. findViewById them).
Also, I have the impression this bug started acting up after setting "anyDensity=true" in AndroidManifest.xml
I've just had the exact same issue except with CLAMP TileMode. I have a bitmap that I want to then just stretch away at the bottom and have it set up as an XML defined BitmapDrawable and in the Graphical Preview window all looks fine, no matter what size I make the ViewImage it draws my bitmap at the top and then repeats the last pixels to fill to the end.
Launching the app on various SDK builds on the emulator and on my own phone all then produced a straight 'fill' type distortion which is completely useless.
The solution turned out to simply be to re-apply the TileMode every time I changed the size of the ImageView within my code:
((BitmapDrawable)ascender.getDrawable()).setTileModeY(TileMode.CLAMP);
Now it's all drawing fine. So yes, this looks like a bug to me.
As I didn't see the link here, this was confirmed to be a bug in Android. It was fixed in ICS. See XML drawable Bitmap tileMode bug? for more details.
There is a lot of noise about this topic online, with various (and numerous) suggested solutions.
If you're still at a loss, my suggestion is to keep all tiled bitmap
resources to square, base-2 dimensions.
ie: 16px by 16px for an xhdpi tile asset.
I hoped that the Android platform would "over-tile" to fill a space if the bitmap did not tessellate perfectly - and then trim the waste. However trialling a 10px*10px tiled bitmap across mdpi, hdpi and xhdpi (and v2.3 to v4.0)'inconsistently' showed this stretching.
The base-2 dimension allows for whole and even division as you progress through the various resolutions and as each device tries to paint the tiles each time the view is created.
In Android development, we contest with the ranging hardware and the vendors dipping their fingers into the platform - sometimes this sort of trivial black magic just works.
This appears to have resolved the issue for me at least. Worth a shot.
This sounds like a bug, although I've never seen it myself. If you have a simple APK that reproduces the issue, please send it to me (romainguy /at/ android.com) or file a bug here.
This blog entry discusses the issue
combined with this solution from Tapas listed by Ivo van der Wijk, it works for me.
The key was to remove the tiled setting from the XML, then set it to tiled at runtime. It does not work for me if they are both set to tiled.
Edit: actually, I lied. Even with this it seems to sometimes fail to tile.
Would be very nice to have a reliable work-around.
Edit 2: setting it to something else (eg. CLAMPED) then setting it back so far seems to be working.
I moved my image from drawable-xhdpi to drawable folder and everything was fine.
I was also having the same issue. What I was missing was that we need to add scaletype to fitXY in the imageview for the xml bitmap to work properly.
tile_bitmap.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/tile"
android:tileMode="repeat" />
layout.xml
<ImageView
android:layout_width="match_parent"
android:src="#drawable/tile_bitmap"
android:layout_height="match_parent"
android:scaleType="fitXY"/>

android cropping drawable

I have a small project in which i download images from internet in the form of drawable and use them in Imageview for which i have provided functionality similar to an Imagebutton but without the gray edges.
The question is that is there any functionality in Android(similar to iphone) by which we can crop the drawable from edges to make them rounded edged drawable...
Even if its a "not-tested-neither-recommended" method, do let me know... i would like to work on this a bit... thanx in advance folks...
I believe this is probably the link you're looking for: How should I give images rounded corners in Android?
I tried doing it with a drawable and nested and elements, but wasn't able to get the image drawable to show properly. Not sure if there's a way to get this working or not.

Categories

Resources