我收到以下错误消息:
01-19 23:31:16.436:E / RenderScript(30603):无法打开共享库(/data/data/com.example.android.rs.hellocompute//lib/librs.mono.so):无法加载库:reloc_library [1313]:1222无法找到'_Z9rsForEach9rs_script13rs_allocationS0 _'...
01-19 23:31:16.436:E / RenderScript(30603):无法打开系统共享库(/system/lib/librs.mono.so):( null)
01-19 23:31:16.444:D / AndroidRuntime(30603):关闭虚拟机
01-19 23:31:16.444:W / dalvikvm(30603):threadid = 1:线程退出时未捕获异常(组= 0x40018560)
01-19 23:31:16.585:E / AndroidRuntime(30603):致命异常:主
01-19 23:31:16.585:E / AndroidRuntime(30603):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.android.rs.hellocompute / com.example.android.rs.hellocompute .HelloCompute}:android.support.v8.renderscript.RSRuntimeException:加载ScriptC脚本失败。
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.ActivityThread.access $ 1500(ActivityThread.java:124)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:968)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.os.Handler.dispatchMessage(Handler.java:99)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.os.Looper.loop(Looper.java:130)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.ActivityThread.main(ActivityThread.java:3806)
01-19 23:31:16.585:E / AndroidRuntime(30603):at java.lang.reflect.Method.invokeNative(Native Method)
01-19 23:31:16.585:E / AndroidRuntime(30603):at java.lang.reflect.Method.invoke(Method.java:507)
01-19 23:31:16.585:E / AndroidRuntime(30603):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
01-19 23:31:16.585:E / AndroidRuntime(30603):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-19 23:31:16.585:E / AndroidRuntime(30603):at dalvik.system.NativeStart.main(Native Method)
01-19 23:31:16.585:E / AndroidRuntime(30603):引起:android.support.v8.renderscript.RSRuntimeException:加载ScriptC脚本失败。
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.support.v8.renderscript.ScriptC。(ScriptC.java:69)
01-19 23:31:16.585:E / AndroidRuntime(30603):at com.example.android.rs.hellocompute.ScriptC_mono。(ScriptC_mono.java:41)
01-19 23:31:16.585:E / AndroidRuntime(30603):at com.example.android.rs.hellocompute.HelloCompute.createScript(HelloCompute.java:64)
01-19 23:31:16.585:E / AndroidRuntime(30603):at com.example.android.rs.hellocompute.HelloCompute.onCreate(HelloCompute.java:49)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-19 23:31:16.585:E / AndroidRuntime(30603):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
01-19 23:31:16.585:E / AndroidRuntime(30603):... 11更多
我猜这个消息是由int id
在ScriptC_mono.java中创建的,尽管它应该是R.raw.mono
,但我找不到原因。这是我的* .rs和MainActivity.java文件:
MainActivity:
import android.app.Activity;
import android.os.Bundle;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.support.v8.renderscript.*;
import android.widget.ImageView;
public class HelloCompute extends Activity {
private Bitmap mBitmapIn;
private Bitmap mBitmapOut;
private RenderScript mRS;
private Allocation mInAllocation;
private Allocation mOutAllocation;
private ScriptC_mono mScript;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBitmapIn = loadBitmap(R.drawable.data);
mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
mBitmapIn.getConfig());
ImageView in = (ImageView) findViewById(R.id.displayin);
in.setImageBitmap(mBitmapIn);
ImageView out = (ImageView) findViewById(R.id.displayout);
createScript();
out.setImageBitmap(mBitmapOut);
}
private void createScript() {
mRS = RenderScript.create(this);
mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
mOutAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono);
mScript.forEach_root(mInAllocation, mOutAllocation);
mOutAllocation.copyTo(mBitmapOut);
mScript.destroy();
}
private Bitmap loadBitmap(int resource) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
return BitmapFactory.decodeResource(getResources(), resource, options);
}}
Mono.rs:
#pragma version(1)
#pragma rs java_package_name(com.android.example.hellocompute)
rs_allocation gIn;
rs_allocation gOut;
rs_script gScript;
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y) {
float4 f4 = rsUnpackColor8888(*v_in);
float3 mono = dot(f4.rgb, gMonoMult);
*v_out = rsPackColorTo8888(mono);
}
void filter() {
rsForEach(gScript, gIn, gOut, 0);
}
答案 0 :(得分:1)
这个问题将在下一个SDK版本中修复(由于缺少rsForEach()和其他功能,许多其他版本已经解决了这个问题。)
答案 1 :(得分:0)
我终于找到了解决方案:
我只是使用ScriptIntrinsic并使用ScriptIntrinsicColorMatrix中的方法setColorMatrix(3fMatrix m)修改了具有特定红色组件的矩阵。
感谢您的所有想法,这对我有用!