我试图从[1]创建源代码示例,因为我想使用数据类型"整数"将数据从Java交换到Renderscript,反之亦然.此示例中的所有内容都工作正常,但我无法将数据从RenderScript恢复为Java.我可以在Debug输出中看到计算出的值,但是使用return mScript.get_numberC();将返回0.我也在尝试[2],但这也行不通.那么有没有可能从RenderScript接收数据而不使用Allocation?另一个问题是我如何将Allocations 2 Integer Arrays传递给RenderScript并在不使用的情况下获取一个计算出的数组rsPackColorTo8888(mono)?因为我的应用程序不会与图形相关.
我想用renderscript做一些实验,所以我开始使用sdk附带的示例,但不幸的是我无法编译它.是否有任何额外的工具,我可能需要编译和构建该示例,我试图阅读文档.但他们没有提到任何东西.
Sample项目的问题是......
我在构建项目之后知道eclipse将在res/raw文件夹和gen文件夹中的一些文件中生成新文件,并且这些文件可以在java文件中使用,但是这些文件没有生成.任何人都可以指导我如何解决这个错误.
谢谢,
我一直在尝试运行示例代码包中给出的HelloCompute示例,但我遇到了一个问题.
我将所有renderscript代码放在一个名为"mono.rs"的文件中,如下所示(当然我的包名称)
无论如何,每当我尝试使用该语句引用应该从该文件反射的java类时
private ScriptC_mono mScript;
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说安卓工作室"无法解析符号'ScriptC_mono'".
我的方法有问题吗?是否有一些方法可以使renderscript文件反映出来.我在最近的错误报告中发现了一些关于renderscript错误的内容,但它似乎已在22.0.4中得到修复.
我试图获得一个android.renderscript.Allocation对象将其结果写入int数组.代码很短,但我很难解读如何修复它.
int[] result = new int[bitmap.getWidth() * bitmap.getHeight()];
inAllocation = Allocation.createFromBitmap(mRS, src,Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
outAllocation = Allocation.createTyped(mRS, inAllocation.getType());
outAllocation.copyTo(result);
Run Code Online (Sandbox Code Playgroud)
我得到的例外是:
10-15 19:21:07.084: E/AndroidRuntime(9021): Caused by: android.renderscript.RSIllegalArgumentException: 32 bit integer source does not match allocation type UNSIGNED_8
Run Code Online (Sandbox Code Playgroud)
我的预感是我需要通过内置函数的Androids创建int数组,但无法围绕我应该使用的东西.如果我将方法(和结果对象)的返回类型更改为位图,代码正在工作 - 但我想返回数组形状的像素.
谢谢
嗨,我是一个新手,并尝试在Renderscript中编码.我想知道如何使用渲染脚本在数组中执行元素的总和.有没有办法可以将输出传递回脚本以便顺序添加?我的问题陈述是:矢量和
描述:计算数组中值的总和.
输入:整数数组
输出:整数
任何帮助将非常感激!
我使用Android NDK(使用C++ API for Renderscript)开发了3个C/RS/Neon-Intrinsics版本的视频处理算法.来自JAVA前端的NDK侧的C/RS/Neon呼叫将进入本地级别.我发现由于某种原因,与C和RS版本相比,Neon版本消耗大量功率.我使用Trepn 5.0进行功率测试.
有人可以澄清一下这些方法C,Renderscript - GPU,Neon Intrinsics的功耗水平.哪个消费最多?
RS代码的理想功耗水平是多少?,因为GPU以较低的时钟频率运行,功耗必须更低!
视频 - 1920x1080(20帧)
我在 Android 上使用 renderscript 来编辑照片,目前由于 Android 上的纹理大小限制和内存限制,如果我尝试任何太大的东西,例如使用设备相机拍摄的照片,应用程序将崩溃。
我解决这个问题的第一个想法是使用 BitmapRegionDecoder 并将大照片平铺成可管理的部分,通过渲染脚本编辑它们并一次保存一个,然后使用 PNGJ 将它们拼接在一起 - 一个允许编写 PNG 的 PNG 解码和编码库图像分部分存入磁盘,因此我的内存中没有完整图像。
这工作正常,但将其拼接在一起需要相当长的时间 - 大约 1 分钟。
还有其他我应该考虑的解决方案吗?如果那里有解决方案,我可以更改为 JPEG,但我还没有找到。基本上我正在寻找 BitmapRegionDecoder 的另一面,一个 BitmapRegionEncoder。
为了清楚起见,我不想调整图像大小。
我正试图进入渲染脚本,并对分配使用感到困惑.几乎所有示例都显示了下一个算法:
像这样的东西:
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
Allocation allocationIn = Allocation.createFromBitmap(renderScript, srcBitmap);
Allocation allocationOut = Allocation.createFromBitmap(renderScript, dstBitmap);
scriptColorMatrix.setGreyscale();
scriptColorMatrix.forEach(allocationIn, allocationOut);
//no difference after removing this line
allocationOut.copyTo(dstBitmap);
imagePreview.setImageBitmap(dstBitmap);
Run Code Online (Sandbox Code Playgroud)
这有效,但即使我通过删除省略步骤4也可以工作:
allocationOut.copyTo(dstBitmap);
Run Code Online (Sandbox Code Playgroud)
让我们进一步降低灰度后的亮度:
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
Allocation allocationIn = Allocation.createFromBitmap(renderScript, srcBitmap);
Allocation allocationOut = Allocation.createFromBitmap(renderScript, dstBitmap);
scriptColorMatrix.setGreyscale();
scriptColorMatrix.forEach(allocationIn, allocationOut);
//reset color matrix
scriptColorMatrix.setColorMatrix(new Matrix4f());
//adjust brightness
scriptColorMatrix.setAdd(-0.5f, -0.5f, -0.5f, 0f);
//Performing forEach vise …Run Code Online (Sandbox Code Playgroud) 我试图使用RenderScript创建一个模糊的位图,将其设置为包含ImageView的LinearLayout的背景.我还想要一个清晰的位图原始副本,以便我可以在ImageView中将其设置为图像.
这是我的代码:
ImageView mainImage;
Bitmap mainBMP, blurredBMP
LinearLayout background;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_area);
getImage(); // obtain bitmap from file
mainImage.setImageBitmap(mainBMP); // set the original bitmap in imageview
// create a blurred bitmap drawable and set it as background for linearlayout
BitmapDrawable drawable = new BitmapDrawable(getResources(), blur(mainBMP));
mainBackground.setBackground(drawable);
registerForContextMenu(objectImage);
registerForContextMenu(textArea);
}
private void getImage(){
String filename = getIntent().getStringExtra("image");
try {
FileInputStream is = this.openFileInput(filename);
mainBMP = BitmapFactory.decodeStream(is);
is.close();
} …Run Code Online (Sandbox Code Playgroud) 我想重载一个RenderScript内核:
/* donothing.rs */
uchar4 __attribute__((kernel, overloadable)) root (uchar4 in) {
return in;
}
float4 __attribute__((kernel, overloadable)) root (float4 in) {
return in;
}
Run Code Online (Sandbox Code Playgroud)
但是,这会生成同名的Java方法:
// ScriptC_donothing.java:95
public void forEach_root(Allocation ain, Allocation aout, Script.LaunchOptions sc) {
// check ain
if (!ain.getType().getElement().isCompatible(__U8_4)) {
throw new RSRuntimeException("Type mismatch with U8_4!");
}
...
// ScriptC_donothing.java:225
public void forEach_root(Allocation ain, Allocation aout, Script.LaunchOptions sc) {
// check ain
if (!ain.getType().getElement().isCompatible(__F32_4)) {
throw new RSRuntimeException("Type mismatch with F32_4!");
}
...
Run Code Online (Sandbox Code Playgroud)
有没有办法编写内核以使重载有效?我预期的用法是:
// DoNothingActivity.java
mInAllocation = …Run Code Online (Sandbox Code Playgroud) renderscript ×10
android ×8
bitmap ×2
java ×2
android-ndk ×1
arrays ×1
blur ×1
c ×1
neon ×1
overloading ×1