I would like to have a color picker in my app looking like this
I've tried fill bitmap pixel by pixel, tried use canvas with drawArc()
method. Both ways are not good for performance.
Any ideas?
It might not be precisely what it should be (related to colors, saturation and so on), but here is something that start to look like what you want....
import android.graphics.*;
import android.graphics.drawable.Drawable;
public class HSV_Circle extends Drawable {
Paint p = new Paint();
@Override
public void draw(Canvas canvas) {
int width = canvas.getWidth();
int height = canvas.getHeight();
int min = Math.min(width,height);
RadialGradient radial_gradient = new RadialGradient(width/2, height/2, min/2, 0xFFFFFFFF,
0x00FFFFFF, android.graphics.Shader.TileMode.CLAMP);
int colors[] = new int[13];
float hsv[] = new float[3];
hsv[1]=1;
hsv[2]=1;
for (int i=0; i<12; i++) {
hsv[0] = (360 / 12) * i;
colors[i] = Color.HSVToColor(hsv);
}
colors[12] = colors[0];
SweepGradient sweep_gradient = new SweepGradient(width/2, height/2, colors, null);
ComposeShader shader = new ComposeShader(sweep_gradient, radial_gradient, PorterDuff.Mode.SRC_OVER);
p.setDither(true);
p.setShader(shader);
canvas.drawCircle(width/2, height/2, min/2, p);
}
@Override
public void setAlpha(int i) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.OPAQUE;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With