Android:从renderscript的像素数组创建分配
我正在尝试使用Android Renderscript模糊图像。我的输入是一个包含像素颜色的整数数组。以下是我做过的和没有做过的。Galaxy S设备上的应用程序已关闭,但未显示任何错误消息Android:从renderscript的像素数组创建分配,android,allocation,renderscript,Android,Allocation,Renderscript,我正在尝试使用Android Renderscript模糊图像。我的输入是一个包含像素颜色的整数数组。以下是我做过的和没有做过的。Galaxy S设备上的应用程序已关闭,但未显示任何错误消息 bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); Allocation input = Allocation.createSized(rs, Element.I32(rs), p
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
Allocation input = Allocation.createSized(rs, Element.I32(rs), pixels.length);
input.copy1DRangeFrom(0, pixels.length, pixels);
Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(6f);
script.setInput(input);
script.forEach(output);
output.copyTo(pixels);
您需要查看logcat输出(确保androidstudio/Eclipse中没有打开任何过滤器),它将显示崩溃
您看到的问题很可能是因为您的输入
分配元素类型与输出不匹配。它们必须是一样的。与其调用Allocation.createSize()
并指定一个元素,只需调用并为其提供输入Bitmap
对象即可。然后将输入的位图
复制到分配
如果日志中没有错误,应用程序将停止在“output.copyTo”行。在我的例子中,我没有位图,输入是一个包含像素的数组。从该数组创建位图以用于分配不是一个解决方案,因为它会减慢进程,我需要速度,这是一个实时进程。logcat中必须有一些内容,所有崩溃都会被记录,即使是在本机代码或RS中,也必须创建位图或将其放入字节数组中,这样分配才能与U8_4兼容。