Is it possible to disable anti-aliasing on vector images? - android

On Wear OS in ambient mode, only black or white pixels should be displayed (no grays). Anti-aliasing a black and white image introduces gray pixels. Now, anti-alising can be disabled for a TextView by writing textView.paint.isAntiAlias = false (in Kotlin) but there doesn't seem to be an equivalent for vector images. The one thing I've tried is adding android:antialias="false" to the image XML file, but it seems to have no effect.

I don't think there is a way to do it in XML.
Personally I've only done this when drawing straight to a canvas. Setting setAntiAlias(false) (don't remember if we ended up using setDither(false) and setFilterBitmap(false) too) on the Paint did the trick.
You can try using a DrawableWrapper and make the necessary changes in the draw() method. Unfortunately this means that you have to set all your drawables in code, but at least you'll still be able to rely on an ImageView.

Related

Android Bitmap - Replace an object's color keeping Anti-Aliasing

I have an image in my assets folder on which I am drawing stuff using an external program and then using them in my app. The problem is that the bitmaps are blank (transparent) with black and white objects in them. Note that the objects are created with Anti-Aliasing on to look better. I know this was asked before but I couldn't find what I want. I need to replace all the black and white pixels in the image (even the transparent anti-aliased ones!) to the colors given by the user. Below are some images to show what I want to do:
Please note that this is just an example and I have even some very complicated shapes and the final colors aren't known (as inputed by the user in RGB style).
Any help is appreciated. Thanks! :)
Usually you can tint the images you load apliying them a color at runtime.
The problem is that color applies to the whole image and it only matchs exactly the same color in white pixels, with or without alpha.
So you could separate all the areas of the image with the same color, save them as white and then tint them at runtime while overlapping one over another.
It depends on the framework you are using.

How to add an outer shadow for a rounded-corners drawable?

I'm using this RoundedCorners library (based on Romain Guy's post) which allows to set both outline border and a rounded rectangular image to an imageView .
I need to add an outer shadow (meaning it's outside of the image being shown) to the image that is shown (say ,to direction south-east) . I've decided that since the border is the larger part of what is shown, I would add the shadow to it instead of to the image, using the next extra code in RoundedDrawable :
mBorderPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Of course, I've also added the fields and populated them with values.
Problem is, the shadow seem to ignore the dx,dy values i've given it, and it's just setting the background to the entire imageView .
I've read here and some people claim that using setShadowLayer on new android API (from 11+) won't work except on texts because it tries to use the GPU , but I've tested it on API10 too and it had the same result.
How could it be? What should I do in order to fix it or use an alternative?
I assume I could add a new paint like the one used for the border, but this would mean I need to change a lot more code that depends on it too (or actually I need to do it anyway? ) . Plus, i might make it a little uglier than what is shown for real shadows.

Custom gradient actionbar background, not display well, need dither

I use a linear background (xml shape) as the actionbar background in android 4.0. It does not display well, looks banded.
How to make it render smooth?
First, I'm assuming you're using the default RGBA_8888 pixel format (default as of Android 2.3). Second, on some displays gradients render poorly. One workaround is to overlay a small bit of noise over the gradient (a repeating semi-transparent noise texture in drawable-nodpi should do) using a <layer-list> drawable.
Try increasing PixelFormat quality of a window:
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getWindow().setFormat(PixelFormat.RGBA_8888);
}
This is possibly a duplicate of this question.
Is it a repeating pattern (tiled) or a nine patch?
ICS is having some issues with certain types of rendering since it is by default drawing using hardware acceleration which makes it impossible to use some drawing techniques (specially when Drawables) and generates undesired results with some others. You can see some explanation and a list here.
Fortunately there are solutions or workarounds to most of them. Just need to know which exact kind of element are you using to draw your background.

Quality of rendering shadow in transparent png on Android

When using a transparent PNG image which has a fine fading shadow always there is an edge line around the shadow on the Android screen. It does not show this in emualator or Exclipse. See photo.
I wonder if there is way to improve on this. Is this something to do with inability of Android screen to show all 24 bit colours or the fact that is scaling and resampling image?
In this example the image is loaded into an ImageButton view. I tried it as source or background and it is the same quality.
The artefact you are seeing is known as "banding" and it is a consequence of your display being 16bits per pixel.
The best way to resolve this is to add some "noise" to your image asset in Photoshop or Paint.NET.
Alternatively you can set your window to be 32bpp with the following line added to your activity's onCreate(), between super.onCreate() and setContentView(). :
getWindow().setFormat(PixelFormat.RGBA_8888);

Mach Banding images in Android

I used a linear gradient image for a background and in Photoshop (and everything else) it looks nice and smooth but when I displayed it in the emulator is was banded! What's worse, it's banded on my actual phone - a Droid Incredible. I'm running 2.2 both in emulation and on the phone.
Here's a sample - original on the left, Android'ed version on the right: http://pnart.com/temp/AndroidMach.jpg
This has the appearance of Android imposing some bit-depth limitation. What's going on and how do I fix it?
Thanks in advance!
I had the same problem and did some searching on Google. One of the sites I found suggested I put the gradient image in res/raw/ and load the image when needed. I tried this and it worked.
From what little I understand, any image you place under "drawable" will be processed by AAPT and it isn't guaranteed the final images will be the same as the ones you are putting into it. In this case, it decided to shrink the PNG gradient image to a smaller palette to shrink the size of the final APK. If someone else has a better (or more correct) explanation, I'd love to hear.
-Dan
just try this: get down the width and height to the screen resolution of the device (eg: for moto droid: w:320px and h:480px and in photoshop keep the resolution to 200 dpi or above)
Regards,
Mistry Hardik
If there isn't any special reason for using an image to get a gradient I highly recommend looking up the Shape Drawable as it supports gradients which should (I haven't tried it but I assume) allow lossless scaling.
First of all, the color depth of phone's screen is much worse than that of your PC. On your PC you have 8-8-8 bits depth for R-G-B but for phones it's typical to have 5-6-5 depth. It means that any fine gradients/shades that look good on PC will be distorted when displayed on the device because its color depth is just not enough, physically.
Therefore, designer's rule №1: avoid fine shades and fine gradients in your designs.
But if you have to then, of course, you may try the following, but you've been warned!
1) For runtime-generated gradients: use dithering, like this:
setContentView(R.layout.screen_dashboard);
findViewById(R.id.layout).getBackground().setDither(true);
2) For graphics assets: always apply a 5-6-5 filter before saving png. Here is a good article with examples. Applying 5-6-5 filter ensures that color depth of your png is within device capabilities, and decreases png size too.
Seems like it might be because it's scaling the image to fit the screen. When non-vector gradients are scaled they often get that "banded" look. Try making a gradient that's the same size as the screen you're targeting, or try changing the ImageView (or whatever) that is displaying the image to make sure it's not stretching or scaling the image.
EDIT
In my opinion the best solution would be to create your gradient for your background at runtime have a look at GradientDrawable

Categories

Resources