php圖片添加高斯模糊的方法是什么

這篇文章主要介紹“php圖片添加高斯模糊的方法是什么”,在日常操作中,相信很多人在php圖片添加高斯模糊的方法是什么問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”php圖片添加高斯模糊的方法是什么”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

成都做網(wǎng)站、網(wǎng)站建設(shè)的關(guān)注點(diǎn)不是能為您做些什么網(wǎng)站,而是怎么做網(wǎng)站,有沒有做好網(wǎng)站,給成都創(chuàng)新互聯(lián)一個(gè)展示的機(jī)會(huì)來證明自己,這并不會(huì)花費(fèi)您太多時(shí)間,或許會(huì)給您帶來新的靈感和驚喜。面向用戶友好,注重用戶體驗(yàn),一切以用戶為中心。

 private static Bitmap activityShot(Activity activity) {
 
        /*獲取windows中最頂層的view*/
        View view = activity.getWindow().getDecorView();
        //允許當(dāng)前窗口保存緩存信息
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache(true);
 
//        //獲取狀態(tài)欄高度
//        Rect rect = new Rect();
//        view.getWindowVisibleDisplayFrame(rect);
//        int statusBarHeight = rect.top;
//
//        WindowManager windowManager = activity.getWindowManager();
//
//        //獲取屏幕寬和高
//        DisplayMetrics outMetrics = new DisplayMetrics();
//        windowManager.getDefaultDisplay().getMetrics(outMetrics);
//        int width = outMetrics.widthPixels;
//        int height = outMetrics.heightPixels;
//
//        //去掉狀態(tài)欄
//        Bitmap shotBitmap = Bitmap.createBitmap(view.getDrawingCache(), 0, statusBarHeight, width,
//                height - statusBarHeight);
 
        //壓縮系數(shù)2,4,8
        float scaleFactor = 8;
        Bitmap scaledBitmap = Bitmap.createBitmap(
                (int) (view.getMeasuredWidth() / scaleFactor),
                (int) (view.getMeasuredHeight() / scaleFactor),
                Bitmap.Config.ARGB_8888);
 
        Canvas canvas = new Canvas(scaledBitmap);
        canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
        canvas.scale(1 / scaleFactor, 1 / scaleFactor);
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        // 截屏view.getDrawingCache()
        canvas.drawBitmap(view.getDrawingCache(), 0, 0, paint);
        //銷毀緩存信息
        view.destroyDrawingCache();
        view.setDrawingCacheEnabled(false);
        return scaledBitmap;
    }

將return的scaleBitmap放入下面的方法:

private static Bitmap rsBlur(Context context, Bitmap source, int radius) {
        Bitmap inputBmp = source;
        //(1)
        //初始化一個(gè)RenderScript Context
        RenderScript renderScript = RenderScript.create(context);
        // Allocate memory for Renderscript to work with
        //(2)
        //創(chuàng)建輸入輸出的allocation
        final Allocation input = Allocation.createFromBitmap(renderScript, inputBmp);
        final Allocation output = Allocation.createTyped(renderScript, input.getType());
        //(3)
        // Load up an instance of the specific script that we want to use.
        //創(chuàng)建ScriptIntrinsic
        ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
        //(4)
        //填充數(shù)據(jù)
        scriptIntrinsicBlur.setInput(input);
        //(5)
        // Set the blur radius
        //設(shè)置模糊半徑
        scriptIntrinsicBlur.setRadius(radius);
        //(6)
        // Start the ScriptIntrinisicBlur
        //啟動(dòng)內(nèi)核
        scriptIntrinsicBlur.forEach(output);
        //(7)
        // Copy the output to the blurred bitmap
        //copy數(shù)據(jù)
        output.copyTo(inputBmp);
        //(8)
        //銷毀renderScript
        renderScript.destroy();
        return inputBmp;
    }

不用的時(shí)候要remove掉:

    public void removeMask(){
        if (group != null){
            for(int i=0;i<group.getChildCount();i++){
                group.removeView(imageView);
            }
        }
    }

到此,關(guān)于“php圖片添加高斯模糊的方法是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

新聞標(biāo)題:php圖片添加高斯模糊的方法是什么
分享地址:http://muchs.cn/article12/ijdcdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站收錄App設(shè)計(jì)、App開發(fā)、品牌網(wǎng)站制作、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司