从github下载StackBlur的调整使用

背景动态模糊效果的实现

Android StackBlur这个库能够基于渐变或radius对一个Bitmap进行模糊化处理。该函数库兼容Android 1.5版本(所以几乎与每个设备都可兼容)。

它是由 kikoso 开源的可对位图图像实现模糊效果( blurry effect),可采用 gradient 或者 radius 的方式。 该库使用了 Mario Klingemann 的算法代码。

android-stackblur

开源地址: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值