1. 程式人生 > >從github下載StackBlur的調整使用

從github下載StackBlur的調整使用

背景動態模糊效果的實現

Android StackBlur這個庫能夠基於漸變或radius對一個Bitmap進行模糊化處理。該函式庫相容Android 1.5版本(所以幾乎與每個裝置都可相容)。

它是由 kikoso 開源的可對點陣圖影象實現模糊效果( blurry effect),可採用 gradient 或者 radius 的方式。 該庫使用了 Mario Klingemann 的演算法程式碼。

android-stackblur

具體下載下來之後,匯入eclipse中有錯誤,不能執行demo,以下是要做的修改:

1、修改project.properties檔案,註釋後半部分內容:

# Project target.
target=android-20
android.library=true
#renderscript.target=18
#renderscript.support.mode=true
#sdk.buildtools=18.1.0

# Project target.
target=Google Inc.:Google APIs:21
android.library.reference.1=../StackBlur
#renderscript.target=18
#renderscript.support.mode=true
#sdk.buildtools=18.1.0


2、當執行是直接會崩潰,原因是空指標異常,原因是資源地址錯誤,解決辦法是:https://github.com/kikoso/android-stackblur/issues/23

Hi, I'm talking about the views in my Android Aplication project, not in the library, I've checked the views that the activity contains,(StackBlurDemo project has the same R weird error), and found that the views in fact are there, but with a different ID:

R.id.textView1 in R class has id = 0x07090009

but after referenced StackBlur Libraryin runtime has changed the ID

R.id.textView1 in R class at runtime has id = 0x070A0009

The ID has increased in a 0x10000 value, I've tried using

findviewbyid(R.id.textView1 + 0x10000) and it works!! (Doesn't return null)

I don't understand why reference a library can change the id of a view in runtime, I think its a problem with a RenderScript and the Eclipse compiler

Finally to get working your library in my demo project, had to remove the RenderScript code (the .rs file, remove the render lines in project.properties and the ones in .java too) and now I can see how fast is the natively process!

在id後面加上0x10000,這個原因的產生是引入庫專案造成的,具體原因也不明白。同時menu的layout和item的id也要加上這個值。

3、執行之後的processNatively方法是失效的,解決辦法是重新編譯生成so檔案,做法是從終端進到庫專案的資料夾,修改Android.mk檔案:

LOCAL_PATH := $(call my-dir)
 
# Create BitmapUtils library
 
include $(CLEAR_VARS)
 
LOCAL_LDLIBS    := -llog -ljnigraphics
 
LOCAL_MODULE    := blur
LOCAL_SRC_FILES := blur.c
 
LOCAL_CFLAGS    =  -ffast-math -O3 -funroll-loops
 
include $(BUILD_SHARED_LIBRARY)

# Renderscript support library is not available for ARM before v7a currently
#ifneq ($(TARGET_ARCH_ABI),armeabi)
#	# Add prebuilts for Renderscript Support
#	include $(CLEAR_VARS)
#
#	LOCAL_MODULE := librsjni
#	LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/librsjni.so
#
#	include $(PREBUILT_SHARED_LIBRARY)
#
#	include $(CLEAR_VARS)
#
#	LOCAL_MODULE := libRSSupport
#	LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libRSSupport.so
#	include $(PREBUILT_SHARED_LIBRARY)
#endif


同樣是註釋下半部分程式碼,然後執行ndk-build(前提是配置了ndk環境變數)。

成功之後再執行demo就部分恢復了功能,因為processRenderScript方法還沒實現,報錯是:找不到檔案R.raw.blur,仍未解決。

##以上只是在eclipse做的方式,在Android Studio的方法可能不同。

我的Demo:http://download.csdn.net/detail/xunfan/8384241(eclipse版本)

解決上述RenderScript的模糊實現的方法:對於渲染指令碼方法的修改,我是看了一篇部落格之後有了解決辦法:http://imgtec.eetrend.com/article/2003

就是修改ScriptC_blur的例項化方法為:ScriptC_blur blurScript = new ScriptC_blur(_rs);

然後在匯入這個專案的時候你肯定還有其他的問題,可以在github上的問題解答區裡的16樓和26樓分別得到解決。地址:https://github.com/kikoso/android-stackblur/issues