Android Renderscript Allocation.USAGE_SHARED崩溃 [英] Android Renderscript Allocation.USAGE_SHARED crash

查看:169
本文介绍了Android Renderscript Allocation.USAGE_SHARED崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行使用renderscript的应用程序时出现崩溃。不幸的是,logcat没有提供任何具体细节。

  b = Bitmap.createBitmap(ib.getWidth(),ib.getHeight (),ib.getConfig()); 

分配mInAllocation = Allocation.createFromBitmap(mRS,inBitmap,
Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_SHARED);

分配mOutAllocation2 = Allocation.createFromBitmap(mRS,
outBitmap,Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SHARED);

...从.rs文件执行算法,然后执行以下操作

  mOutAllocation2.copyTo(outBitmap)`; 

当我对mOutAllocation2使用USAGE_SCRIPT标志而不是USAGE_SHARED时,相同的代码序列运行得很好。 p>

为什么会发生这种情况的任何帮助?



我在android文档中读到,如果分配类型为USAGE_SHARED ,那么从分配到位图的复制操作(参见上文)会更快。
当前,我看到从分配到位图的副本在几秒钟内就可以处理相当大的图像(8MP及以上)



我正在使用Nexus 10(Android 4.3)目前。

解决方案

首先,您需要使用Allocation.USAGE_SCRIPT |分配。USAGE_SHARED。



第二,如果您的复制时间花了那么长的时间,您可能还会看到脚本的执行情况。脚本执行是异步的,因此copyTo(Bitmap)的挂钟时间可能不仅包括副本,还包括更多时间。


I am getting a crash while running my app which uses renderscript. Unfortunately, the logcat does not give any specific details.

b = Bitmap.createBitmap(ib.getWidth(), ib.getHeight(),ib.getConfig());

Allocation mInAllocation = Allocation.createFromBitmap(mRS, inBitmap,
                Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_SHARED);

Allocation mOutAllocation2 = Allocation.createFromBitmap(mRS,
                 outBitmap, Allocation.MipmapControl.MIPMAP_NONE,
                 Allocation.USAGE_SHARED);

...execute an algorithm from .rs file and later do the below

mOutAllocation2.copyTo(outBitmap)`;

The same code sequence runs perfectly fine, when I used USAGE_SCRIPT flag instead of USAGE_SHARED for mOutAllocation2.

Any help on why this could happen?

I read in android docs that if the allocation is of the type USAGE_SHARED, then the copy operation from allocation to the bitmap (see above) is faster. Currently, I am seeing copies from allocation to bitmaps running into secs for decently large images (8MP and above)

I am using Nexus 10 (Android 4.3) currently.

解决方案

First, you need to be using Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED. createFromBitmap(RenderScript, Bitmap) will set that for you when possible.

Second, if your copy times are taking that long, you're probably seeing script execution as well. Script execution is asynchronous, so the wall clock time of copyTo(Bitmap) may include significantly more than just the copy.

这篇关于Android Renderscript Allocation.USAGE_SHARED崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆