Monday, 15 July 2013

android - How to preallocate RadialGradient? -



android - How to preallocate RadialGradient? -

i'm drawing circles on canvas. want apply radial gradient each of circle. i'm allocating new gradient each circle, i'm guessing not idea.

protected void ondraw(canvas canvas) { int radius = 6; int cx = radius; int cy = radius ; for(int = 0; < nbpage; i++) { if(i % 12 == 0 && > 0) { cx = radius; cy += 20; } radialgradient gradient = new radialgradient(cx, cy, radius, 0xffffffff, 0xff000000, android.graphics.shader.tilemode.clamp); p.setdither(true); p.setshader(gradient); canvas.drawcircle(cx, cy, radius, p); cx += 20; //16px + 4 de marge } }

is there solution preallocate radial gradient knowing each circle have same radius differents coordinates ?

thanks

take radialgradient object , draw bitmap, proceed draw bitmap canvas each circle.

bitmap circlebitmap = bitmap.create((int) (radius * 2.0f), (int) (radius * 2.0f), bitmap.config.argb_8888); canvas tempcanvas = new canvas(circlebitmap); radialgradient gradient = new radialgradient(cx, cy, radius, 0xffffffff, 0xff000000, android.graphics.shader.tilemode.clamp); p.setdither(true); p.setshader(gradient); tempcanvas.drawcircle(radius, radius, radius, p); (int = 0; < nbpage; i++) canvas.drawbitmap(circlebitmap, cx + (i * 20) - radius, cy - radius, p);

android android-canvas gradient radial-gradients

No comments:

Post a Comment