Skip to content

可设置遮罩的 ImageView,支持 Canvas 绘制的遮罩

License

Notifications You must be signed in to change notification settings

l0neman/MaskImageView

Repository files navigation

MaskImageView

可添加遮罩的ImageView,可在外部通过canvas绘制遮罩,内置椭圆和圆角矩形两种遮罩,可选择Xfermode或BitmapShader绘制遮罩

round

round

使用

  • 直接在布局中使用
<com.runing.view.MaskImageView
    android:id="@+id/miv_content"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:src="@drawable/img0"
    app:center="true"
    app:mask_mode="xfermode"
    app:mask_shape="circle" />
  • 在代码中设置自定义遮罩
mMaskImageView.setDrawMask(new MaskImageView.DrawMask() {
    Path mPath = new Path();

    @Override
    public void onDrawMask(Canvas canvas, Paint paint, @Px int viewW, @Px int viewH) {
        mPath.reset();
        mPath.moveTo(viewW / 4, 0);
        mPath.lineTo(viewW / 4 * 3, 0);
        mPath.lineTo(viewW, viewH);
        mPath.lineTo(0, viewH);
        mPath.close();
        canvas.drawPath(mPath, paint);
    }
});

round

About

可设置遮罩的 ImageView,支持 Canvas 绘制的遮罩

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages