欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android RenderScript高斯模糊

 更新時間:2016年11月19日 09:29:52   作者:寄意蘭州  
這篇文章主要介紹了Android RenderScript高斯模糊的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

今天先說說ScriptIntrinsicBlur,這個類不需要定義rs文件,從這個Intrinsic單詞可以看的出來,它是API17以后內(nèi)置的類,專門用來處理圖像的,讓圖片變模糊。

public static Bitmap blurBitmap(Bitmap bitmap, float radius, Context context) { 
    //創(chuàng)建渲染腳本上下文 
    RenderScript rs = RenderScript.create(context); 
 
    //為位圖分配內(nèi)存 
    Allocation allocation = Allocation.createFromBitmap(rs, bitmap); 
 
    Type t = allocation.getType(); 
 
    //用同樣的類型創(chuàng)建內(nèi)存,一般用這兩種方式創(chuàng)建 <span style="font-family: Arial, Helvetica, sans-serif;">Allocation</span> 
    Allocation blurredAllocation = Allocation.createTyped(rs, t); 
 
    //創(chuàng)建高斯渲染腳本  
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 
    //設置模糊半徑 (maximum 25.0) 
    blurScript.setRadius(radius); 
    //為腳本設置輸入?yún)?shù)  
    blurScript.setInput(allocation); 
    //調(diào)用腳本 結(jié)果存入 <span style="font-family: Arial, Helvetica, sans-serif;">blurredAllocation中</span> 
    blurScript.forEach(blurredAllocation); 
 
    //把腳本結(jié)果存入位圖中 因為為native層渲染,所以結(jié)果需要復制到上層 
    blurredAllocation.copyTo(bitmap); 
 
    //Destroy everything to free memory 
    allocation.destroy(); 
    blurredAllocation.destroy(); 
    blurScript.destroy(); 
    t.destroy(); 
 
    return bitmap; 
  } 

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論