在画布绘制的形状周围创建阴影? [英] Creating a shadow around a canvas drawn shape?

查看:84
本文介绍了在画布绘制的形状周围创建阴影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建形状需要执行哪些步骤,例如

What steps are required to create a shape e.g. rectangle with a shadow from scratch using a Canvas?

在用于绘制矩形的油漆中添加阴影层没有成功。

Adding a shadow layer to the paint used to draw the rectangle yielded no success.

推荐答案

无需位图,只需将图层类型设置为 LAYER_TYPE_SOFTWARE

No need for a Bitmap, just needed to set the layer type to LAYER_TYPE_SOFTWARE the original approach worked.

public class TestShapeShadow extends View
{
    Paint paint;

    public TestShapeShadow(Context context)
    {
       super(context);  

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setShadowLayer(12, 0, 0, Color.YELLOW);

        // Important for certain APIs 
        setLayerType(LAYER_TYPE_SOFTWARE, paint);
    }

    @Override
    protected void onDraw(Canvas canvas)
    {   
        canvas.drawRect(20, 20, 100, 100, paint);
    }
}

这篇关于在画布绘制的形状周围创建阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆