Android RenderScript开发问题

时间:2014-10-21 19:22:58

标签: android constructor renderscript

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

描述资源路径位置类型 构造函数ScriptC_simplers(RenderScript,Resources,int)未定义MainActivity.java / SimpleRS / src / com / benchmark / simplers第57行Java问题

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

我使用的是Eclipse ADT,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找不到构造函数。如果你知道解决方案,请帮助我,谢谢你!

1 个答案:

答案 0 :(得分:0)

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