我想在我的应用程序中使用RenderScript框架模糊位图。我正在使用下面的代码:ScriptIntrinsicBlur产生黑色位图
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius)
{
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
}
不幸的是,我所得到的代码是黑色的位图。我该如何解决这个问题?
位图传递到下面的方式创建的apply
方法:
Bitmap b = Bitmap.createBitmap(thisView.getWidth(),
thisView.getHeight(),
Bitmap.Config.ARGB_8888);
这些位图的宽度和高度的4
倍数也有通过的renderScript但我报道了一些错误不知道它们是什么意思,我应该如何解决它们(ScriptIntrinsicBlur
的文档很薄)。下面是这些错误:
20305-20391/com.xxx E/RenderScript﹕ rsi_ScriptIntrinsicCreate 5
20305-20391/com.xxx E/RenderScript﹕ rsAssert failed: mUserRefCount > 0, in
frameworks/rs/rsObjectBase.cpp at 112
编辑:
半径是5和我运行在三星Galaxy Nexus的应用与Android 4.2.1。
运行中设置的“半径”是多少?什么版本的Android?查看rsObjectBase.cpp代码,日志断言不在4.3.1或4.4.2源文件中。 –
@LarrySchiefer我已经更新了我的问题。你能看一下吗? – Bobrovsky
您使用支持库吗?你应该使用支持库。 –