Skip to content Skip to sidebar Skip to footer

How To Preallocate Radialgradient?

I'm drawing some circles on a canvas. I want to apply a radial gradient to each of this circle. I'm currently allocating a new gradient for each circle, but i'm guessing this not a

Solution 1:

Take the RadialGradient object and draw it to a Bitmap, then proceed to draw that Bitmap to the Canvas for 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);

for (int i = 0; i < nbPage; i++)
    canvas.drawBitmap(circleBitmap, cx + (i * 20) - radius, cy - radius, p);

Post a Comment for "How To Preallocate Radialgradient?"