Android RenderScript高斯模糊_Android

來源:互聯網
上載者:User

看代碼的時候,看到了其中有.rs結尾的檔案,不是很明白,還有RenderScript類,看的一臉蒙蔽,不知所云,然後百度了一下,收貨還真不少,這東西在圖形處理這塊用處挺大的。

今天先說說ScriptIntrinsicBlur,這個類不需要定義rs檔案,從這個Intrinsic單詞可以看的出來,它是API17以後內建的類,專門用來處理映像的,讓圖片變模糊。

public static Bitmap blurBitmap(Bitmap bitmap, float radius, Context context) {     //建立渲染指令碼上下文     RenderScript rs = RenderScript.create(context);      //為位元影像分配記憶體     Allocation allocation = Allocation.createFromBitmap(rs, bitmap);      Type t = allocation.getType();      //用同樣的類型建立記憶體,一般用這兩種方式建立 <span style="font-family: Arial, Helvetica, sans-serif;">Allocation</span>     Allocation blurredAllocation = Allocation.createTyped(rs, t);      //建立高斯渲染指令碼      ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));     //設定模糊半徑 (maximum 25.0)     blurScript.setRadius(radius);     //為指令碼設定輸入參數      blurScript.setInput(allocation);     //呼叫指令碼 結果存入 <span style="font-family: Arial, Helvetica, sans-serif;">blurredAllocation中</span>     blurScript.forEach(blurredAllocation);      //把指令碼結果存入位元影像中 因為為native層渲染,所以結果需要複製到上層     blurredAllocation.copyTo(bitmap);      //Destroy everything to free memory     allocation.destroy();     blurredAllocation.destroy();     blurScript.destroy();     t.destroy();      return bitmap;   } 

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.