首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImageView - ColorFilter

ImageView - ColorFilter
EN

Stack Overflow用户
提问于 2015-03-24 12:35:59
回答 1查看 429关注 0票数 0

我有一个ImageView,并使用ColorFilter (PorterDuff.Mode.MULTIPLY)。

是否可以使用这个colorFilter,但不能在整个图像上使用?它一定是一个‘边缘’/‘填充’。

例如:图像宽度和高度=100 and。但是colorFilter必须是ImageView中心的50 be (宽度和高度)。

下面的图片是我需要的(red = colorFilter)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-24 19:38:11

您可以子类ImageView并重写其onDraw()方法。我张贴了一个极简的解决方案,修改你的需要!

代码语言:javascript
复制
public class OverlayImageView extends ImageView {
    Paint paint;
    float padding = 30;

    public OverlayImageView(Context context) {
        super(context);
        init();
    }

    public OverlayImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public OverlayImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
        paint.setColor(Color.RED);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawRect(padding, padding, canvas.getWidth()-padding, canvas.getHeight()-padding, paint);
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29232815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档