Android学习笔记进阶17之LinearGradient

具体的看一下博文:Android学习笔记进阶15之Shader渲染

 

package xiaosi.BitmapShader;

import android.app.Activity;
import android.os.Bundle;

public class BitmapShaderActivity extends Activity {
    /** Called when the activity is first created. */
	private BitmapShaders bitmapShaders = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        bitmapShaders = new BitmapShaders(this);
        setContentView(bitmapShaders);
    }
}


BitmapShaders.java

package xiaosi.BitmapShader;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposeShader;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.view.View;

public class BitmapShaders extends View
{
	private LinearGradient linearGradient = null;
	private ComposeShader composeShader = null;
	private SweepGradient sweepGradient = null;
	private RadialGradient radialGradient = null;
	private BitmapShader bitmapShader = null;
	private Bitmap bitmap = null;
	private Paint paint = null;
	private ShapeDrawable shapeDrawable = null;
	private int BitmapWidth = 0;
	private int BitmapHeight = 0;

	public BitmapShaders(Context context)
	{
		super(context);
		// 得到图像
		bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.v))
				.getBitmap();
		BitmapWidth = bitmap.getWidth();
		BitmapHeight = bitmap.getHeight();
		// 构造渲染器LinearGradient
		linearGradient = new LinearGradient(0, 0, 100, 100, new int[] {
				Color.RED, Color.GREEN, Color.BLUE, Color.WHITE }, null,
				Shader.TileMode.REPEAT);
		paint = new Paint();
	}

	@Override
	protected void onDraw(Canvas canvas)
	{
		super.onDraw(canvas);
		paint.setShader(linearGradient);
		canvas.drawRect(20, 50, 320, 156, paint);
	}
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值