• Android 图片高级绘图效果---高斯模糊


    高斯模糊就是将指定像素变换为其与周边像素加权平均后的值,权重就是高斯分布函数计算出来的值。高斯模糊能够将图片制作成类似磨砂的图片效果,一般这些图片都用来作为背景。
    目前使用到的是RenderScript ,其特点是使用起来比较方便,虽然效率不是很高,但是也能够满足目前的使用。使用流程如下:

    1. 添加混淆配置

    -keepclasseswithmembernames class * {
        native <methods>;
    }
    -keep class android.support.v8.renderscript.** { *; }

     2.使用高斯模糊

    private void blur(Bitmap bkg, View view) {
    
            float radius = 25;
    
            Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth()), (int) (view.getMeasuredHeight()), Bitmap.Config.ARGB_8888);
    
            float scaleW = (float) view.getMeasuredWidth() / (float) bkg.getWidth();
            float scaleH = (float) view.getMeasuredHeight() / (float) bkg.getHeight();
    
            Matrix matrix = new Matrix();
            matrix.postScale(scaleW, scaleH);
            Bitmap resizeBmp = Bitmap.createBitmap(bkg, 0, 0, bkg.getWidth(), bkg.getHeight(), matrix, true);
    
            Canvas canvas = new Canvas(overlay);
    
            canvas.translate(-view.getLeft(), -view.getTop());
            canvas.drawBitmap(resizeBmp, 0, 0, null);
    
            RenderScript rs = RenderScript.create(this);
    
            Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay);
    
            ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
    
            blur.setInput(overlayAlloc);
    
            blur.setRadius(radius);
    
            blur.forEach(overlayAlloc);
    
            overlayAlloc.copyTo(overlay);
            view.setBackground(new BitmapDrawable(getResources(), overlay));
            rs.destroy();
        } 

  • 相关阅读:
    [中文] 以太坊(Ethereum )白皮书
    走近比特币:一个故事看懂“区块链”
    MAC下redis的安装和配置
    mysql查询优化
    mac上用VMWare虚拟机装Linux-Ubuntu
    rest-framework框架
    浅谈设计模式
    [BZOJ3786]星系探索(欧拉序+非旋treap)
    [SDOI2017]遗忘的集合(多项式ln+生成函数+莫比乌斯反演)
    [LuoguP4841]城市规划(多项式ln+生成函数)
  • 原文地址:https://www.cnblogs.com/renhui/p/9528316.html
Copyright © 2020-2023  润新知