我正在尝试在Android中实现一些用Renderscript编写的代码,但是遇到了不同的问题。 首先,让我说一下,我所有的SDK包都升级到了22.3版本,包括Ecplise ADT和Build-Tools 19.0.0。
我的目的是在广泛的Android平台上实现一些高计算图像算法,可能从API 8开始。为此,我在Ecplise项目中引用了renderscript-v8
库,同时将应用程序的目标定位为API 19。
我有两个Android设备进行测试,第一个是Android 4.3(API 18),第二个是带有Android 2.2(API 8)的设备。运行这段代码时,它调用ScriptIntrinsicYuvToRGB(代码部分来自执行ScriptIntrinsicYuvToRgb问题),我遇到了不同的异常情况。
/* --------------
global vars */
private RenderScript rs;
private ScriptIntrinsicYuvToRGB rs_YUVtoRGB;
private Allocation rs_YUVtoRGB_in;
private Allocation rs_YUVtoRGB_out;
/* --------------
in constructor... */
this.rs = RenderScript.create(this.getContext());
this.rs_YUVtoRGB = ScriptIntrinsicYuvToRGB.create(this.rs, Element.U8_4(rs));
Type.Builder tb_in = new Type.Builder(this.rs, Element.createPixel(this.rs, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
tb_in.setX(prevWidth);
tb_in.setY(prevHeight);
tb_in.setMipmaps(false);
tb_in.setYuvFormat(this.camera.getParameters().getPreviewFormat());
this.rs_YUVtoRGB_in = Allocation.createTyped(this.rs, tb_in.create(), Allocation.USAGE_SCRIPT);
Type.Builder tb_out = new Type.Builder(this.rs, Element.RGBA_8888(this.rs));
tb_out.setX(prevWidth);
tb_out.setY(prevHeight);
tb_out.setMipmaps(false);
this.rs_YUVtoRGB_out = Allocation.createTyped (this.rs, tb_out.create(), Allocation.USAGE_SCRIPT);
/* --------------
launching the script... */
// byte[] raw... // a YUV image
this.rs_YUVtoRGB_in.copyFrom(raw);
this.rs_YUVtoRGB.setInput(this.rs_YUVtoRGB_in);
this.rs_YUVtoRGB.forEach(this.rs_YUVtoRGB_out);
int[] framePixels = new int[previewSize.width * previewSize.height];
this.rs_YUVtoRGB_out.copyTo(framePixels); // final RGB converted image
Eclipse可以编译它(这应该意味着库已经被正确引用),但是......
Android 4.3在以下代码处失败:Type.Builder tb_in = new Type.Builder(this.rs, Element.createPixel(this.rs, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
报错信息为不支持的DataKind
11-24 11:17:57.685: E/AndroidRuntime(2494): FATAL EXCEPTION: main
11-24 11:17:57.685: E/AndroidRuntime(2494): android.renderscript.RSIllegalArgumentException: Unsupported DataKind
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.renderscript.Element.createPixel(Element.java:911)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.support.v8.renderscript.ElementThunker.createPixel(ElementThunker.java:224)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.support.v8.renderscript.Element.createPixel(Element.java:832)
11-24 11:17:57.685: E/AndroidRuntime(2494): at com.lag.appprj.CameraPreview.setupCamera(CameraPreview.java:167)
11-24 11:17:57.685: E/AndroidRuntime(2494): at com.lag.appprj.CameraPreview.surfaceCreated(CameraPreview.java:86)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView.updateWindow(SurfaceView.java:571)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView.access$000(SurfaceView.java:86)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
在Android 2.2上,它在初始化阶段失败:加载RS jni库时出错:java.lang.UnsatisfiedLinkError: 找不到库RSSupport
11-24 11:45:45.329: E/AndroidRuntime(2048): FATAL EXCEPTION: main
11-24 11:45:45.329: E/AndroidRuntime(2048): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lag.appprj/com.lag.appprj.CaptureActivity}: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.os.Looper.loop(Looper.java:123)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-24 11:45:45.329: E/AndroidRuntime(2048): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 11:45:45.329: E/AndroidRuntime(2048): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-24 11:45:45.329: E/AndroidRuntime(2048): at dalvik.system.NativeStart.main(Native Method)
11-24 11:45:45.329: E/AndroidRuntime(2048): Caused by: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:945)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:982)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:968)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.lag.appprj.CameraPreview.<init>(CameraPreview.java:80)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.lag.appprj.CaptureActivity.onCreate(CaptureActivity.java:34)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
感谢你的帮助。