Most efficient way to show frame by frame animation android

前端 未结 8 1861
醉话见心
醉话见心 2021-02-01 07:41

I am trying to show frame by frame animation by changing images in a imageview. I tried animation drawable in xml and also changing the bitmap of the imageview inside a Handler.

8条回答
  •  别跟我提以往
    2021-02-01 07:57

    Loading the bitmaps from assets instead of resources saved 40% decoding time for me. You might want to try that.

    So this went from 5 seconds with resources to 3 seconds on your pictures on my 2012 Nexus 7:

    long time = System.currentTimeMillis();
    try {
        for (int i = 0; i < 35; i++) {
            InputStream assetStream = getAssets().open(
                    "_step" + (i + 1) + ".png");
            try {
                Bitmap bitmap = BitmapFactory.decodeStream(assetStream);
                if (bitmap == null) {
                    throw new RuntimeException("Could not load bitmap");
                }
                mBitmaps.add(bitmap);
            } finally {
                assetStream.close();
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Log.d("ANIM", "Loading bitmaps elapsed "+(System.currentTimeMillis() - time)+"ms");
    

提交回复
热议问题