Question

How do I properly use the RenderScript Intrinsics.

as shown http://android-developers.blogspot.com/2013/08/renderscript-intrinsics.html

//Assuming my original Bitmap is "bm"
Bitmap outputBitmap = Bitmap.createBitmap(bm.getHeight(),
bm.getWidth(), Config.ARGB_8888);

RenderScript rs = RenderScript.create(getApplicationContext());
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur
.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, bm);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(25.f);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
bm.recycle();
rs.destroy

I get some black areas of the outputBitmap on initial layout, but which get filled in after the user scrolls the Scroller of the HorizontalScrollView, making the drawable "refresh" itself.

I get this error too (if it helps):

09-01 05:54:11.246: E/RenderScript(11423): rsAssert failed: !mElements.size(), in frameworks/rs/rsElement.cpp at 375

any suggestions regarding proper use of the RS will help.

enter image description here

Was it helpful?

Solution

I think the problem is that you switched the order of the height and width arguments. It should be:

Bitmap outputBitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Config.ARGB_8888);

OTHER TIPS

I'm guessing you've got some issue with the UI parts rather than the RS parts. The RS parts look fine; maybe try a outputBitmap.prepareToDraw() after the RS bits have finished?

Note that in general it's not a great idea to create and destroy RS contexts in the critical path like that. There's potentially a nontrivial startup/teardown cost depending on the hardware resources that have to be allocated, so it would be much better to allocate it at startup and use it for the lifetime of the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top