简体   繁体   English

为什么我不能强制我的一个视图在软件中渲染?

[英]Why can't I force one of my Views to render in software?

In a custom view I have, I'm using Canvas.drawBitmap with a source Bitmap that is wider than 2048px. 在我的自定义视图中,我使用Canvas.drawBitmap,其源位图比2048px宽。 This of course causes problems when Hardware Acceleration is enabled, with the LogCat spewing out "W/OpenGLRenderer(4968): Bitmap too large to be uploaded into a texture" each time drawBitmap is called. 这当然会在启用硬件加速时引起问题,每次调用drawBitmap时,LogCat会喷出“W / OpenGLRenderer(4968):位图太大而无法上传到纹理”。

So to work around this I tried calling setLayerType(View.LAYER_TYPE_SOFTWARE, null) on my view. 所以为了解决这个问题,我尝试在我的视图上调用setLayerType(View.LAYER_TYPE_SOFTWARE, null) The only problem is that it doesn't seem to help. 唯一的问题是它似乎没有帮助。 When I try to run my app, LogCat will still give the warnings, and nothing ends up being drawn. 当我尝试运行我的应用程序时,LogCat仍然会发出警告,并且最终都不会被绘制。

I cannot understand why is this so. 我不明白为什么会这样。 This article on the Android site clearly states: Android网站上的这篇文章明确指出:

You can disable hardware acceleration for an individual view at runtime with the following code: 您可以使用以下代码在运行时禁用单个视图的硬件加速:

 myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

Is there something I'm doing wrong? 有什么我做错了吗? Why is Android not respecting the setLayerType call? 为什么Android不尊重setLayerType调用?


[in case it matters: I'm performing my testing on a Samsung Galaxy Tab 10.1 running Android 3.2] [万一重要:我正在运行Android 3.2的三星Galaxy Tab 10.1上进行测试]

Try to resize the bitmap first. 尝试先调整位图大小。 Use createBitmap. 使用createBitmap。

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

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