Monday, 10 September 2012

Example of RadialGradient

Example of RadialGradient:

RadialGradient


Modify onDraw(Canvas canvas) method of MyView.java in the exercise of LinearGradient.

 @Override
protected void onDraw(Canvas canvas) {

float w, h, cx, cy, radius;
w = getWidth();
h = getHeight();
cx = w/2;
cy = h/2;

if(w > h){
radius = h/4;
}else{
radius = w/4;
}

canvas.drawRect(0, 0, w, h, BackPaint);

Paint MyPaint = new Paint();
MyPaint.setStyle(Paint.Style.FILL);

float shaderCx = 0;
float shaderCy = 0;
float shaderRadius = w;
int shaderColor0 = Color.WHITE;
int shaderColor1 = Color.BLACK;
MyPaint.setAntiAlias(true);
Shader radialGradientShader;

radialGradientShader = new RadialGradient(
shaderCx, shaderCy, shaderRadius,
shaderColor0, shaderColor1,
Shader.TileMode.MIRROR);

MyPaint.setShader(radialGradientShader);
canvas.drawRect(0, 0, w, h, MyPaint);

shaderCx = cx;
shaderCy = cy;
shaderRadius = radius;
shaderColor0 = Color.RED;
shaderColor1 = Color.BLUE;

radialGradientShader = new RadialGradient(
shaderCx, shaderCy, shaderRadius,
shaderColor0, shaderColor1,
Shader.TileMode.MIRROR);

MyPaint.setShader(radialGradientShader);
canvas.drawCircle(cx, cy, radius, MyPaint);
};


download filesDownload the files.

- More samples of drawing on canvas.

Borneo08

About Borneo08

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :

More links

Related Posts Plugin for WordPress, Blogger...