在Android ImageView的消减滤波器(切出从图像或视图对象的羽毛椭圆形) [英] Subtractive Filter on Android ImageView (Cut-out a feathered oval from an image or view object)

查看:335
本文介绍了在Android ImageView的消减滤波器(切出从图像或视图对象的羽毛椭圆形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何砍出一个洞羽毛在ImageView的。

I'm trying to figure out how to "cut-out a feathered hole" in an ImageView.

其理由是,我创建一个教程,我想整个屏幕暗淡。这是很容易被50%左右放置一个黑色图像与阿尔法做。接下来,我想开一个洞成叠加,这样你就可以更清楚地看到什么是它的下面。记住我们的目标是要突出按钮和东西的用户点击,所以他们学着做什么。

The reasoning is, I am creating a tutorial, and I want the whole screen dim. That's easy enough to do by placing a black image with alpha around 50%. Next I want to cut a hole into that overlay, so you can more clearly see what's underneath it. The goal in mind is to highlight buttons and things for the user to click on, so they learn what to do.

当我这样做之前,在ActionScript / Flash中,很容易只放了点心字母在屏幕上,然后创建一个圆,它的规模是X'放大器; Y以匹配我想强调的对象,然后添加一个过滤器将其设置为减去它的混合模式。这种消减圆形/椭圆形也被告知接受鼠标点击,孔的东西伟大的工作。

When I did this before in ActionScript / Flash, it was easy to just put a dim-alpha over the screen, then create a circle, scale it's X & Y to match the object I want to highlight, then add a filter to it with it's blend mode set to SUBTRACT. This subtractive circle/oval could also be told to accept mouse clicks, and the hole thing worked great.

在Android中,我似乎无法看到如何从意见中减去。我可以看到使用彩色滤光片的人加入到一个视图或改变颜色。

In android, I can't seem to see how to subtract from views. I can see people using color filters to add to a view or change the colors.

所以,除非我错过了船,你怎么减?

So, unless I am missing the boat, how do you subtract?

推荐答案

您需要编写自定义绘制对象类,并将其分配给您的ImageView。然后,你可以在这样的抽签方法很容易地做到这一点:

You need to write a custom Drawable class and assign it to your ImageView. Then you can do this easily in the draw method like this:

class MyDrawable extends Drawable {

    @Override
    public void draw(Canvas canvas) {
        Path path = new Path();
        path.setFillType(FillType.EVEN_ODD);

        // This will create a full screen rectangle.
        path.addRect(<screen size rect here>, Path.Direction.CW);

        // This will punch a hole in it
        path.addCircle(<x>, <y>, <radius>, Path.Direction.CCW);

        // Now draw everything on the Canvas
        Paint paint = new Paint();
        paint.setColor(<dim color here>);
        canvas.drawPath(path, paint);
    }

要使它很好地突出了工作的时候,你可以把你想在这个drawable的构造函数来突出显示。然后你可以使用确定视图的位置是:

To make it work nicely when highlighting, you can pass the View you want to highlight in this Drawable's constructor. Then you can determine the position of the view using:

int[] position = new int[2];
view.getLocationOnScreen(position);

使用此和视图的高度和宽度来确定的圆的尺寸和位置。

Use this and the view's height and width to determine the size and position of the circle.

我不知道这是否会工作,但你也可以尝试这样做羽化切口:

I don't know if this will work, but you can also try feathering the cutout by doing this:

paint.setMaskFilter(new BlurMaskFilter(20, BlurMaskFilter.Blur.NORMAL));

这篇关于在Android ImageView的消减滤波器(切出从图像或视图对象的羽毛椭圆形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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