Android RenderScript开发问题

Android RenderScript开发问题,android,constructor,renderscript,Android,Constructor,Renderscript,我正在尝试运行我的第一个RenderScript应用程序。但我有以下问题: 首先是错误消息: 说明资源路径位置类型 构造函数ScriptC_simplersRenderScript,Resources,int是未定义的MainActivity.java/SimpleRS/src/com/benchmark/SimpleRS第57行java问题 ScriptC_simplers类型中的方法forEach_rootAllocation,Allocation不适用于参数Allocation,Alloc

我正在尝试运行我的第一个RenderScript应用程序。但我有以下问题: 首先是错误消息:

说明资源路径位置类型 构造函数ScriptC_simplersRenderScript,Resources,int是未定义的MainActivity.java/SimpleRS/src/com/benchmark/SimpleRS第57行java问题

ScriptC_simplers类型中的方法forEach_rootAllocation,Allocation不适用于参数Allocation,Allocation MainActivity.java/simplers/src/com/benchmark/simplers line 60 java问题

我使用的是EclipseADT,API级别为19.1.0

已成功生成R.java文件和ScriptC_simplers.java。 以下是MainActivity文件:

package com.benchmark.simplers;


import android.app.Activity;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.renderscript.Allocation;
import android.renderscript.RenderScript;
import android.renderscript.ScriptC;
import android.widget.ImageView;

import android.support.v8.renderscript.*;


public class MainActivity extends Activity {
private Bitmap mBitmapIn;
private Bitmap mBitmapOut;


private RenderScript mRS;
private Allocation mInAllocation;
private Allocation mOutAllocation;
private ScriptC_simplers mScript;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBitmapIn = loadBitmap(R.drawable.android);
    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);
    out.setImageBitmap(mBitmapOut);


    createScript();
}

private void createScript() {
    mRS = RenderScript.create(this);


    mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
    Allocation.MipmapControl.MIPMAP_NONE,
    Allocation.USAGE_SCRIPT);
    mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());


    mScript = new ScriptC_simplers(mRS, getResources(), R.raw.simplers);


    mScript.forEach_root(mInAllocation, mOutAllocation);
    mOutAllocation.copyTo(mBitmapOut);
}

private Bitmap loadBitmap(int resource) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    return BitmapFactory.decodeResource(getResources(), resource, options);
}
}

以下是simplers.rs文件:

#pragma version(1)
#pragma rs java_package_name(com.benchmark.simplers)


const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};


void root(const uchar4 *v_in, uchar4 *v_out) {
    float4 f4 = rsUnpackColor8888(*v_in);
    float3 mono = dot(f4.rgb, gMonoMult);
    *v_out = rsPackColorTo8888(mono);
}
在生成的文件ScriptC_simplers.java中,我可以看到构造函数:

public  ScriptC_simplers(RenderScript rs, Resources resources, int id) {
    super(rs, resources, id);
    __U8_4 = Element.U8_4(rs);
}

我只是不知道为什么ADT找不到构造函数。如果你知道解决方案,请帮助我,谢谢你

您正在混合使用android.renderscript.*和android.support.v8.renderscript.*,这是不允许的。您最终导入了两个不同版本的分配,因此很可能无法获得您想要的版本。您是想让一个简单的RS应用程序使用常规RS还是支持库版本来工作?删除其中一组导入,看看这是否会改变行为。

您好,我有点困惑。如果我想使用RenderScript进行并行计算,我应该导入哪一个?非常感谢。如果您不知道,您希望使用android.support.v8.renderscript.*.@CrazyTim在这种情况下,如果可能,请始终使用android.support版本