gpt4 book ai didi

java - 使用 BitmapFactory.decodeByteArray 制作动画时帧速率不均匀

转载 作者:行者123 更新时间:2023-12-02 07:27:13 25 4
gpt4 key购买 nike

我想播放逐帧动画。我有一个 ArrayList byeArr,其中包含 jpeg 图片并将它们一一解码以显示在表面 View 上。

tim = new CountDownTimer(1,1)
{
int i = 0;

@Override
public void onFinish()
{

if ( i < byeArr.size() )
{
bitMap = BitmapFactory.decodeByteArray ( byeArr.get(i) , 0, byeArr.get(i).length );
/// bitMap is a bitmap that is displayed on screen.

lastFrameMs = System.currentTimeMillis() - lastFrameSysTime;
totalFr = totalFr + lastFrameMs;
Log.e("LF", "frame: "+ String.valueOf(i) + " = " + String.valueOf(lastFrameMs) +"ms");

lastFrameSysTime = System.currentTimeMillis();
i++;
tim.start();

}
...

例如,如果我想要 15 FPS 帧稀有,我应该将 CountDownTimer 设置为 1000/15 - lastFrameMs ,其中 lastFrameMs 是绘制一帧的时间。

如果帧能以恒定的速度绘制,这会很好用,但问题是它们不是。每帧可能需要 25 到 65 毫秒...

11-14 19:00:52.402: E/LF(26270): frame: 0 = 60ms
11-14 19:00:52.429: E/LF(26270): frame: 1 = 27ms
11-14 19:00:52.488: E/LF(26270): frame: 2 = 55ms
11-14 19:00:52.519: E/LF(26270): frame: 3 = 32ms
11-14 19:00:52.574: E/LF(26270): frame: 4 = 57ms
11-14 19:00:52.605: E/LF(26270): frame: 5 = 30ms
11-14 19:00:52.664: E/LF(26270): frame: 6 = 56ms
11-14 19:00:52.695: E/LF(26270): frame: 7 = 33ms
11-14 19:00:52.753: E/LF(26270): frame: 8 = 58ms
11-14 19:00:52.824: E/LF(26270): frame: 9 = 71ms
11-14 19:00:52.886: E/LF(26270): frame: 10 = 62ms
11-14 19:00:52.914: E/LF(26270): frame: 11 = 27ms
11-14 19:00:52.976: E/LF(26270): frame: 12 = 62ms
11-14 19:00:53.007: E/LF(26270): frame: 13 = 29ms
11-14 19:00:53.066: E/LF(26270): frame: 14 = 61ms
11-14 19:00:53.097: E/LF(26270): frame: 15 = 27ms
11-14 19:00:53.171: E/LF(26270): frame: 16 = 77ms
11-14 19:00:53.199: E/LF(26270): frame: 17 = 28ms
11-14 19:00:53.261: E/LF(26270): frame: 18 = 62ms
11-14 19:00:53.300: E/LF(26270): frame: 19 = 37ms
11-14 19:00:53.355: E/LF(26270): frame: 20 = 56ms
11-14 19:00:53.390: E/LF(26270): frame: 21 = 34ms
11-14 19:00:53.457: E/LF(26270): frame: 22 = 66ms
11-14 19:00:53.484: E/LF(26270): frame: 23 = 30ms
11-14 19:00:53.550: E/LF(26270): frame: 24 = 64ms
11-14 19:00:53.582: E/LF(26270): frame: 25 = 31ms
11-14 19:00:53.640: E/LF(26270): frame: 26 = 60ms
11-14 19:00:53.667: E/LF(26270): frame: 27 = 29ms
11-14 19:00:53.734: E/LF(26270): frame: 28 = 66ms
11-14 19:00:53.769: E/LF(26270): frame: 29 = 33ms
11-14 19:00:53.828: E/LF(26270): frame: 30 = 60ms
11-14 19:00:53.871: E/LF(26270): frame: 31 = 43ms
11-14 19:00:53.929: E/LF(26270): frame: 32 = 58ms
11-14 19:00:53.933: E/- - -(26270): - - -
11-14 19:00:53.933: E/fps(26270): 21 FPS
11-14 19:00:53.933: E/avrg ms for frame(26270): 46

...有什么想法可以对此做些什么吗?

谢谢!

最佳答案

您不应该在解码后立即显示它们。

在计时器中,解码位图,然后等待 X 时间,然后再显示位图。其中 X 是

X = constantInterval - lastFrameMs.

如果 X 为负数,则立即绘制。

此外,如果 RAM 足够小,您应该考虑将动画存储在 RAM 中而不是对其进行解码。

关于java - 使用 BitmapFactory.decodeByteArray 制作动画时帧速率不均匀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385307/

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