Nine patch images look pixelated - android

I use several nine patch images in my layout, for buttons, text fields and form backgrounds. All of the xxx.9.png files are in the drawable-hdpi folder, just like the regular images, yet they still look pixelated.
The ImageView at the top has a regular bitmap and the lower ImageView uses a Nine Patch bitmap. You can see that the Nine Patch bitmap is scaled to a lower density. How do I fix that?

You should put 9 patch images in the nodpi folder, unless you want the non-stretchable area to be scaled/stretched also.

Ah, it was messed up because I was calling canvas.setDensity( 480 ) somewhere in a custom view. That caused this problem.

Related

9patch drawable or separate image in each drawable

Is it better to have separate image in each drawable folder (hdpi, ldpi, ...) or use 9patch drawable?
I want to use 9patch drawable for different screen size but I am not sure which is better. I know that 9patch drawable is better because it we can use only one image instead of several image in each drawable folder.
It seams like you're misunderstanding the intent of Nine-Patch Drawables:
A NinePatch is a PNG image in which you can define stretchable regions that Android scales when content within the View exceeds the normal image bounds.
There's no correlation to the screen density. If you're not using very simple graphics, you might need to add the nine-patch files to each drawable folder anyway.

How to use same Android drawable to all resolutios

I have one big image named panel_bck.jpg to use in different resolutions to decrease apk size. The image format is JPG and it's size is 1.9MB. I put it to default drawable folder only. But when I set the background in code, the BitmapFactory can't find the image at
drawable/panel_bck.jpg
and the result is all black background. I tested this case with other images(PNG files, JPG files) and there is no problem with them. Only question is that a limitation exist for the drawable size or what is the problem? How can I solve this?
If your image very big resoulation you will set drawable-xxhdpi directory only.
I had a problem like yours trying to maka a big image fit into a too small ImageView and I fixed my problem by using this line in the layout xml file:
android:adjustViewBounds="true"
I don't know if it can ba applied to an activity background though.
You should use 9patch image. You can create 9patch image by using the tool called draw9patch located in sdk/tools. First create a large resolution image and give to draw9patch it will create a 9patch image with extension .9.png add that image in drawable it will solve you problem.
See following links for detail
http://developer.android.com/tools/help/draw9patch.html
http://codesignature.com/how-to-design-9-patch-buttons-for-android-using-adobe-photoshop-for-all-pixel-densities-and-states/

How to set image as background for all Android devices so that stretching does not distort it?

Reference the image attached. How to set such an image as background?
Does using 9-patch makes it possible?
Yes, Please Use 9-Patch image and Please check this on how to draw 9-patch image and also this Video Tutorial
Refer to your ldpi, mdpi, hdpi, xhdpi, and xxhdpi folders there you will have to format your image to fit the particular sizes of each screen. Another way of doing it would be android:setbackground="#drawable:example"; in your xml and testing your app out in the emulator on all the different screen sizes to see if it really matters that much due to the simplicity of your image.
It would be much simpler to create a high res .png file in your case. and might end up working better (just a thought)
If attached image is the only case, then you could try and create your own drawable by extending Drawable class.
It's just a rectangle with circles cutout on each side. This can be easily drawn using drawRect and drawCircle. This way you'll get perfect quality on every screen.

Keep sharpness of bitmap colors in stretched imageview

Is it possible to keep the colors of the bitmap in a stretched imageview sharp if this bitmap contains only the colors black and white?
Currently what i get is the bitmap with blurred edges.
I think it would make sense to keep the sharpness of the colors without resizing the bitmap
I know this question is old, but :)
You should provide screenshots with your question so we can see what you're talking about. Anyway, drawables in Android aren't scaled very well so it is normal if you get some blurry effet on a resized bitmap.
You should use the different drawables (drawable-hdpi, -mdpi, xhdpi, ...) folders of your project to provide different versions of your images to the system. The right resource will always be chosen depending on the device screen.

Layer List Drawable - clip bitmap by nine-patch?

I would like to create Drawable that contains nine-patch and a Bitmap.
I put them together in Layer List Drawable, but it turns out that Bitmap is extending nine-patch beyond the edge.
Is there any way to "cut" Bitmap so it won't be overlapping nine-patch?
EDIT: Actually it seems that I would like to shrink background to wrap content and ingore big bitmap in background.
a nine patch by definition doesn't have a size.
From the sounds of things you haven't configured your nine patch correctly.
Please attach an image of what you're seeing and your source files.

Categories

Resources