Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smooth gradient on different devices

In my app i have gradient as drawable which i am using as background and i wan't it to make it look as smooth as possible. After googling and trying by myself i came up with the following. On nexus one if you call only setDither(true) your gradient is still banding so you have to set PixelFormat like this Window.setFormat(PixelFormat.RGBA_8888). But on the other side G1 does not support RGBA_8888 so calling it make the gradient even uglier than before so Window.setFormat(PixelFormat.RGBA_8888) will not work well on devices that don't support it.

What is the correct way smooth my gradient on all devices on which my app will run.

PS: i found some related topics

How to draw a smooth/dithered gradient on a canvas in Android

Is it possible to dither a gradient drawable?

like image 506
Mojo Risin Avatar asked Jul 26 '10 11:07

Mojo Risin


People also ask

How do I smooth a gradient in Illustrator?

To create a smooth looking Gradient or Blend in Illustrator look to these steps. If you are using the Blend Tool and you are getting banding, double-click on the Blend Tool in the Tool Palette. This should bring up a dialog box, make sure the pull-down menu is set to Smooth Color.

How do you find the perfect gradient?

To put it simply, they have to mix colors that are far away from each other on the color wheel. In this case, it is necessary to introduce an in-between element to create a good-looking gradient. It's a so-called 3-stop gradient that uses a new color as the connecting point between the two original colors.

How do I smooth a gradient in Photoshop?

To create smooth gradient transitions, we want to work in 16-bit mode (Image-Mode-16Bits/Channel) to eliminate most of the color banding. Create a new layer for the gradient by selecting Layer-New Fill Layer-Gradient. Accept the default setting and click OK. This will bring up the Gradient Fill dialogue box.


2 Answers

Open your image in Photoshop (or Gimp or Paint.NET or whatever) and add a small quantity of noise. Then you don't have to do anything in code.

like image 157
Reuben Scratton Avatar answered Nov 08 '22 23:11

Reuben Scratton


You can use a custom shape (put it in /drawable/gradient.xml or something like that):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#000000"
    android:endColor="#ffffff"
    android:angle="90"/>
</shape>

This way it will be painted by the os and it should be perfectly smooth.

like image 40
ShadowMare Avatar answered Nov 08 '22 23:11

ShadowMare