画布绘制速度太慢
我正在开发一个允许逐步浏览视频帧(位图)的应用程序。它还能够逐帧播放帧,就好像您实际上正在观看由帧组成的视频一样。
我有一个 ImageView 一次显示一张位图。我遇到的问题是,将图像绘制到 ImageView(我们所说的只是对 super.onDraw() 的调用)大约需要 30 毫秒。由于帧需要以其原始帧速率播放,因此这是一个问题。还有其他正在进行的操作也会减慢进程,但绘图肯定没有帮助。
我正在研究 OpenGL ES,但似乎并非所有设备都支持非二次方图像,因此这不起作用。图像的尺寸是设备记录的视频分辨率的一半,因为我以一半尺寸对它们进行采样,并且几乎可以保证永远不会是二次方图像。
有什么方法可以加快绘图速度吗?
I am working on an app that allows stepping through video frames (bitmaps). It also has the capability to play back the frames, one after another, as though you are actually viewing a video composed of the frames.
I have one ImageView that is showing one bitmap at a time. The problem I am having is that drawing the image to the ImageView (we're talking just a call to super.onDraw()) is taking roughly 30ms. Since the frames need to be playing back at their original framerate, this is a problem. There are other operations going on as well that are also slowing the process down, but the drawing certainly isn't helping.
I was looking into OpenGL ES, but it seems that not all devices support non-power-of-two images, so that won't work. The dimensions of the images are half of the device's recorded video resolution since I am sampling them at half-size, and that's pretty much guaranteed to never be a power-of-two image.
Is there some way I can speed things up so that the drawing is faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OpenGL ES 2.0 强加了对两个纹理的非幂的支持,因此您可以放心使用它。如果您使用 OpenGL ES 1.0 并且没有 2 的幂支持,则很容易解决它(只需创建一个足够大的 2 的幂纹理来包含您的 npot 图像。)
注意:您应该分析您的应用程序以查看是否可以使用 Canvas 提高速度。也许您在绘制时缩小了图像的尺寸,也许它不是兼容的配置,并且转换发生在运行时(例如 565 到 8888),等等。
OpenGL ES 2.0 imposes support of non-power of two textures, so you're safe with it. If you use OpenGL ES 1.0 and you don't have power of two support, it's very easy to work around it (just create a power of two texture big enough to contain your npot image.)
Note: you should profile your app to see whether you can improve the speed with Canvas. Maybe you are downscaling the image at draw time, maybe it's not in a compatible configuration and conversion happens at runtime (565 to 8888 for instance), etc.
我发现 ImageView 从来没有给我我正在寻找的帧速率(原因,我不知道)。对于这样的事情,你应该重写 SurfaceView 。这需要更多的工作,但您肯定会看到帧速率的提高,并且您将拥有更多的灵活性。显然,您需要了解您的剪辑,并知道如果任何其他视图覆盖此视图,也会导致速度显着减慢(因为覆盖层也需要在每一帧上重新绘制)。
I found that ImageView never gave me the framerates I was looking for (the reason, I don't know). For something like this you should override SurfaceView instead. It's a bit more work, but you'll definitely see an improvement in the framerate and you'll have much more flexibility. Obviously you'll want to be aware of your clip and know that if any other view overlays this one, that will cause a significant slowdown as well (since the overlay will also need to be redrawn on each frame).