【问题标题】:Android: Create Allocation from pixels array for renderscriptAndroid:从像素数组为渲染脚本创建分配
【发布时间】:2015-07-26 12:02:44
【问题描述】:

我正在尝试使用 Android Renderscript 来模糊图像。我的输入是一个包含像素颜色的整数数组。这是我做过但没用的。应用程序在 Galaxy S 设备上关闭且没有任何错误消息

    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);

【问题讨论】:

    标签: android allocation renderscript


    【解决方案1】:

    您需要查看 logcat 输出(确保 Android Studio / Eclipse 中没有打开过滤器),它会显示崩溃。

    您看到的问题很可能是因为您的输入 Allocation 元素类型与输出不匹配。它们必须相同。而不是调用Allocation.createSized() 并指定一个元素,只需调用Allocation.createFromBitmap() 并将您的输入Bitmap 对象提供给它。然后将输入的Bitmap复制到Allocation中。

    【讨论】:

    • logcat 中没有错误,应用程序停止在“output.copyTo”行。在我的情况下,我没有位图,输入是一个包含像素的数组。从该数组创建位图以将其用于分配不是解决方案,因为它会减慢过程,我需要速度,这是一个实时过程。
    • logcat 中必须有一些东西,所有的崩溃都会被记录下来,即使它是在本机代码或 RS 中。您必须创建位图或将其保存在字节数组中,以便分配与 U8_4 兼容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多