如何在Android触摸屏上模糊图像的方形部分模糊 [英] How to unBlur square portion of Blurry image on touch android

查看:335
本文介绍了如何在Android触摸屏上模糊图像的方形部分模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么:

在鼠标悬停在模糊图像上时,它会像下面的图像一样以方形显示模糊的相同图像. (图像完全模糊,在鼠标悬停时会以方形显示模糊图像)

On mouse hover of Blurry image, it shows unblur same image in square shape like following image. (image is completely blur, on mouse hover unblur image shown in square shape)

我所做的事情:

我使用以下代码设置了模糊图像( PorterDuff.Mode .触摸屏幕时,鼠标指针将转换为正方形,并且图像显示模糊.

I set blur image using following code (link) using PorterDuff.Mode. On touch of screen mouse pointer converted into square and image shows unblur.

问题:

现在的图片模糊不清,但是我无法对模糊的图像找到合适的模糊效果,模糊的图像也不清楚,触摸时无法正常工作.

Now picture is unblur but i cant find proper blur effect on blurry image and unblur image is also not clear, on touch is not working properly.

我的代码:

使用自定义视图和以下方法,我可以使图像模糊和模糊,但仍然不能完全满足输出要求.

using custom view and following methods i'm able to blur and unblur image but still there's not completely satisfied with output.

@Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(mTutorialColor);
        if (mCx >= 0 && mCy >= 0) {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            int height = displayMetrics.heightPixels;
            int width = displayMetrics.widthPixels;
            // canvas.drawCircle(mCx, mCy, RADIUS, mBackgroundPaint);
            canvas.drawRect(mCx, mCy, mCx + width, mCy + 250, mBackgroundPaint);
        }

    }


private void init() {
        setWillNotDraw(false);
        setLayerType(LAYER_TYPE_HARDWARE, null);
        mBackgroundPaint = new Paint();
        mBackgroundPaint.setColor(getResources().getColor(android.R.color.transparent));
        mBackgroundPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    }

还有其他方法可以实现这一目标吗?

Is there any other way to achieve this?

推荐答案

您需要以不同的方式实现它.

You need to implement it differently.

您需要两张图片(而不是一张):

You need two images (instead of one):

  1. 模糊了一个.始终将其绘制为背景(或在其下方的视图中).在此处阅读如何模糊图像.

正常的.应该使用方形遮罩在模糊的上面绘制一个.选中此 answer .

Normal one. This one should be drawn on top of blurred one using the square mask. Check this answer.

更多详细信息:

可以用相同的方式完成操作,我在此答案中解释的方式却是使用Mode.DST_IN Xfermode PorterDuff.Mode.CLEAR.

It can be done in the same way, how I explained in this answer, but with Mode.DST_IN Xfermode instead of PorterDuff.Mode.CLEAR.

希望这会对您有所帮助.

Hope this will help you.

这篇关于如何在Android触摸屏上模糊图像的方形部分模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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