How to unBlur square portion of Blurry image on touch android

半城伤御伤魂 提交于 2019-12-25 20:37:10

问题


What I want to do:

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)

What I have done:

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


Edit:

Problem:

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.

My Code:

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?


回答1:


You need to implement it differently.

You need two images (instead of one):

  1. Blurred one. Which will be always drawn as background (or in a view underneath). Read here how to blur the image.

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

MORE DETAILS:

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.



来源:https://stackoverflow.com/questions/44392108/how-to-unblur-square-portion-of-blurry-image-on-touch-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!