简体   繁体   English

Android:从像素数组为渲染脚本创建分配

[英]Android: Create Allocation from pixels array for renderscript

I am trying to use the Android Renderscript for blurring an image. 我正在尝试使用Android Renderscript来模糊图像。 My input is an array of integers that containt the pixel's colors. 我的输入是一个包含像素颜色的整数数组。 Here's what I did and not worked. 这是我做过但没做过的事情。 The application shut down without any error message on Galaxy S device 该应用程序已关闭,在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);

You'll need to look at the logcat output (make sure no filters are on in Android Studio / Eclipse), it will show you the crash. 您需要查看logcat输出(确保Android Studio / Eclipse中没有打开任何过滤器),它将显示崩溃。

The problem you're seeing is most likely because your input Allocation element type doesn't match the output. 您看到的问题很可能是因为您的输入Allocation元素类型与输出不匹配。 They need to be the same. 它们必须相同。 Rather than call Allocation.createSized() and specify an element, just call Allocation.createFromBitmap() and provide it with your input Bitmap object. 而不是调用Allocation.createSized()并指定一个元素,只需调用Allocation.createFromBitmap()并为其提供你的输入Bitmap对象。 Then copy the input Bitmap into the Allocation . 然后将输入的Bitmap复制到Allocation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM