简体   繁体   English

RenderScript内在函数高斯模糊

[英]RenderScript Intrinsics Gaussian blur

How do I properly use the RenderScript Intrinsics. 如何正确使用RenderScript内在函数。

as shown http://android-developers.blogspot.com/2013/08/renderscript-intrinsics.html 如图所示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. 我在初始布局中获得了outputBitmap的一些黑色区域,但是在用户滚动Horizo​​ntalScrollView的Scroller之后,它会被填充,使得drawable“刷新”本身。

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. 关于正确使用RS的任何建议都会有所帮助。

在此输入图像描述

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

I'm guessing you've got some issue with the UI parts rather than the RS parts. 我猜你的UI部分而不是RS部分存在问题。 The RS parts look fine; RS部件看起来很好; maybe try a outputBitmap.prepareToDraw() after the RS bits have finished? 可能在RS位完成后尝试输出OutputPitmap.prepareToDraw()?

Note that in general it's not a great idea to create and destroy RS contexts in the critical path like that. 请注意,一般来说,在关键路径中创建和销毁RS上下文并不是一个好主意。 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. 根据必须分配的硬件资源,可能存在非常重要的启动/拆卸成本,因此在启动时分配它并在应用程序的生命周期内使用它会好得多。

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

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