设置
I am using a custom RenderBox
to draw.
The canvas
object in the code below comes from the PaintingContext
in the paint
method.
绘画
I am trying to render pixels individually by using Canvas.drawRect
.
I should point out that these are sometimes larger and sometimes smaller than the pixels on screen they actually occupy.
for (int i = 0; i < width * height; i++) {
// in this case the rect size is 1
canvas.drawRect(
Rect.fromLTWH(index % (width * height),
(index / (width * height)).floor(), 1, 1), Paint()..color = colors[i]);
}
存储
我将像素存储为100(上面代码中的colors
).我以前try 过不同的嵌套列表,但它们在性能方面没有引起任何明显的差异.
我的Android Emulator测试设备increases by 102 when populating the list with a 103 image上的memory.请注意,它只是暂时增加了282.7MB
.大约半分钟后,增量降到153.6MB
,并停留在那里(没有任何用户交互).
渲染
在分辨率为999x999
的情况下,上面的代码导致GPU max为250.1 ms/frame
,UI max为1835.9 ms/frame
,这显然是不可接受的.当试图绘制999x999
图像时,UI会冻结两秒钟,考虑到4k视频在同一设备上运行流畅,这应该是小菜一碟(我猜).
中央处理器
我不确定如何使用Android分析器正确跟踪这一点,但虽然是102 the list,即绘制像素(上述指标也是如此),但中央处理器使用率从0%
上升到60%
.以下是AVD性能设置:
原因
I have no idea where to start since I am not even sure what part of my code causes the freezing. Is it the memory usage? Or the drawing itself?
How would I go about this in general? What am I doing wrong? How should I store these pixels instead.
努力
我试了那么多,但都没有用,所以我只想指出最值得注意的几个:
-
我试着把
List<List<Color>>
改成Image
from thedart:ui
library,希望能用Canvas.drawImage
.为此,我try 对我自己的PNG进行编码,但是I have not been able to render more than a single row.然而,看起来这并不会提振业绩.在try 转换9999x9999
图像时,我遇到内存不足异常.现在,我想知道视频是如何呈现的,因为如果内存中有几秒钟的话,任何4k视频都会很容易比9999x9999
图像占用更多的内存. -
我试着实施
image
计划.然而,在完成它之前,我停了下来,因为我注意到它不是用于Flutter,而是用于HTML.用这个我什么也得不到. -
这一点对于我将得出的以下结论非常重要:我try 了104 without storing the pixels,也就是使用
Random.nextInt
来生成随机 colored颜色 .当try 随机生成999x999
图像时,结果是1824.7 ms/frames
的GPU max和2362.7 ms/frame
的UI max,这更糟糕,特别是在GPU部门.
结论
这是我在try 使用Canvas.drawImage
:Canvas.drawRect
渲染失败之前得出的结论,因为它甚至不能绘制简单的图像.
你是如何在Flutter 打中做到这一点的?
注意事项
-
这基本上是what I tried to ask over two months ago(是的,我一直在努力解决这个问题这么长时间),但我认为我当时没有正确地表达自己,我甚至不知道实际的问题是什么.
-
我能正确渲染的最高分辨率约为
10k
像素.我至少需要1m
个. -
我在想,放弃飘浮,转向本土可能是我唯一的 Select .然而,我愿意相信我处理这个问题是完全错误的.我花了大约三个月的时间试图弄清楚这一点,但我没有找到任何能让我有所作为的东西.