当试图模糊我想使用的图像时
import android.support.v8.renderscript.*
所以我把它放在我的 build.gradle 文件中:
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
}}
我使用这种方法来模糊图像:
public static Bitmap blur(Context ctx, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(ctx);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
但是代码在这一行崩溃了:
RenderScript rs = RenderScript.create(ctx);
给出这个错误:
03-03 14:40:02.965 27865-27865/com.myorder.app E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v8.renderscript.RenderScript
at com.myorder.profile.BlurBuilder.blur(BlurBuilder.java:27)
at com.myorder.ui.SuggestionsHome$1.onResponse(SuggestionsHome.java:70)
at com.myorder.ui.SuggestionsHome$1.onResponse(SuggestionsHome.java:59)
at com.myorder.core.api.dao.impl.AuthDAOImpl$1.onResponse(AuthDAOImpl.java:75)
at com.myorder.core.api.dao.impl.AuthDAOImpl$1.onResponse(AuthDAOImpl.java:62)
at mobvolley.JacksonRequest.deliverResponse(JacksonRequest.java:84)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
我不知道为什么,因为我从这里关注了所有内容:http: //developer.android.com/guide/topics/renderscript/compute.html
任何人都可以帮忙吗?