Merabtene
Merabtene

Reputation: 78

Android: Create Allocation from pixels array for renderscript

I am trying to use the Android Renderscript for blurring an image. 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

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

Upvotes: 1

Views: 620

Answers (1)

Larry Schiefer
Larry Schiefer

Reputation: 15775

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.

The problem you're seeing is most likely because your input Allocation element type doesn't match the output. 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. Then copy the input Bitmap into the Allocation.

Upvotes: 1

Related Questions