gpt4 book ai didi

android - 增加 clipPath 大小会导致滞后

转载 作者:行者123 更新时间:2023-11-29 22:00:02 28 4
gpt4 key购买 nike

我正在循环增加 clipPath 的大小。循环内部还有另一个循环,它创建了更多的 clipPaths,我用它来绘制降低的 alpha,以便获得过渡效果。但随着 clipPath 大小的增加,转换变得缓慢且滞后。

是这样的

int size = 5;
Paint p1 = new Paint();
Path path = new Path();
for (int i = 0; i < 20; i++) {
path.addCircle(centerX, centerY, size, Path.Direction.CCW);
canvas.clipPath(path);
canvas.drawBitmap(bmp2, 0, 0, null);
path.reset();
int incr = size;
while (p1.getAlpha() != 0) {
incr -= 1;
p1.setAlpha(p1.getAlpha() - 5);
path.addCircle(centerX, centerY, incr, Path.Direction.CCW);
canvas.clipPath(path, Op.UNION);
canvas.drawBitmap(bmp2, 0, 0, p1);
path.reset();
}
size += 10;
}

期望的结果

Gradient

我知道这是一个糟糕的方法,但这就是我能想到的。

最佳答案

来自 Hardware Acceleration 的一些提示可能适用:

The following list describes known operations that are not supportedwith hardware acceleration:

Canvas.clipPath()

[...]

Don't create render objects in draw methods

A common mistake is to create a new Paint or a new Path every time a rendering method is invoked. This forces the garbage collector torun more often and also bypasses caches and optimizations in thehardware pipeline.

此外,我在某处读到/听说过,只要您修改路径,就会生成一个 mask 并重新上传到 GPU(?),因此您不应该经常修改它们。所以是的,该代码可能运行不快。

您可能对这些视频感兴趣:

编辑:我不知道实际的替代方法,但如果除了使用路径别无他法,您可以保留它们的数组,而不修改它们。但是,如果动画有很多帧,那可能意味着需要大量内存。

关于android - 增加 clipPath 大小会导致滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12177829/

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