ComposeShader组合渲染

public ComposeShader(Shader shaderA,Shader shaderB, Xfermode mode)
Parameters
shaderA渲染器A,Shader及其子类对象
shaderB渲染器B,Shader及其子类对象
mode 两种渲染器组合的模式,Xfermode对象

public ComposeShader(Shader shaderA,Shader shaderB, PorterDuff.Mode mode)
Parameters

shaderA渲染器A,Shader及其子类对象
shaderB渲染器B,Shader及其子类对象
mode.两种渲染器组合的模式,ProterDuff.Mode对象

主要代码:

public class ComposeShaderActivity extends Activity {
    ImageView image,image2,image3,image4;
    int width,height;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image = (ImageView) findViewById(R.id.image);
        image2 = (ImageView) findViewById(R.id.image2);
        image3 = (ImageView) findViewById(R.id.image3);
        image4 = (ImageView) findViewById(R.id.image4);
        width = ValueUtil.dp2px(this, 120);
        height = ValueUtil.dp2px(this, 120);


        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tupian);

        Bitmap bitmapTemp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmapTemp);
        // 创建BitmapShader对象
        BitmapShader mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.MIRROR,
                Shader.TileMode.MIRROR);
        // 创建LinearGradient并设置渐变颜色数组,平铺效果为镜像
        LinearGradient mLinearGradient = new LinearGradient(0, 0, 0, height, new int[] {
                Color.WHITE, Color.LTGRAY, Color.TRANSPARENT, Color.GREEN }, null,
                Shader.TileMode.MIRROR);
        // 混合渲染 将两个效果叠加,使用PorterDuff叠加模式
        ComposeShader mComposeShader = new ComposeShader(mBitmapShader, mLinearGradient,  PorterDuff.Mode.MULTIPLY);
        Paint paint = new Paint();
        paint.setShader(mComposeShader);
        canvas.drawRect(new RectF(0, 0, width, height), paint);
        image.setImageBitmap(bitmapTemp);
    }
}

效果图:



参考资料:http://blog.csdn.net/t12x3456/article/details/10366131


源码:http://yunpan.cn/c3f2qgcVtNSwP (提取码:2ccf)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值