我想使用 SupportLibrary 中的 RenderScript 来创建模糊效果。
为此,我从这里找到了解决方案 https://stackoverflow.com/a/14988991/408780
final RenderScript rs;
rs = RenderScript.create( myAndroidContext );
final Allocation input = Allocation.createFromBitmap( rs, photo, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT );
final Allocation output = Allocation.createTyped( rs, input.getType() );
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create( rs, Element.U8_4( rs ) );
script.setRadius( myBlurRadius /* e.g. 3.f */ );
script.setInput( input );
script.forEach( output );
output.copyTo( photo );
问题是, rs = RenderScript.create(myAndroidContext) 导致 java.lang.NoClassDefFoundError ,我不知道出了什么问题。
根据https://developer.android.com/reference/android/support/v8/renderscript/ScriptIntrinsicBlur.html ScriptIntrinsicBlur 在版本 23 中添加。
所以我只是在应用程序 gradle 中添加了以下几行:
android {
...
defaultConfig {
...
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
}
...
}
我还尝试了如下所述的 renderscriptTargetApi 21 https://github.com/react-native-community/react-native-blur/issues/110#issuecomment-272956182
但仍然没有成功。有什么建议么?
也许一些额外的信息:
minSdk = 14,targetSdk = 19,compileSdk = 25
先感谢您。