gpt4 book ai didi

android - 解决 android 不再支持的 Canvas.clipPath()

转载 作者:IT老高 更新时间:2023-10-28 22:19:30 36 4
gpt4 key购买 nike

从 android 3.0 开始,clipPath()启用硬件加速的设备不再支持该方法。(阅读此 article 了解更多详细信息)。

我正在使用 Canvas ,我需要绘制圆形图像。关于如何做到这一点的任何想法?

*我无法关闭硬件加速,我正在寻找其他解决方案。

回答:Tnx @Malcolm 为您解答。我找到了一个很好的例子来演示 this technique ,它基本上是一个面具。

最佳答案

clipPath 仅支持 API 级别 18 及更高级别,API 级别从 11 到 17 需要关闭。

你提到的那篇文章有一个线索:

If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by calling setLayerType(View.LAYER_TYPE_SOFTWARE, null). This way, you can still take advantage of hardware acceleratin everywhere else. See Controlling Hardware Acceleration for more information on how to enable and disable hardware acceleration at different levels in your application.

这里的主要思想是在应用程序的部分禁用硬件加速,您需要在 API 级别低于 18 的设备上使用不受支持的方法。您可以针对特定 View 执行此操作,无需转整个应用程序完全关闭。

如果您不想关闭硬件加速,那么我建议您使用 Porter-Duff 模式。您可以创建一个包含一个圆圈的位图,然后使用这种模式将您的图像绘制到 Canvas 上,该模式会将您的图像剪辑到原始内容。

关于android - 解决 android 不再支持的 Canvas.clipPath(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8895677/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com