Android AnimationDrawable Frame Compression


There is a series of frames in png. I make animation using AnimationDrawable.

The frames themselves do not weigh very much, but the situation in RAM is quite deplorable. I wanted to compress each frame using – RGB 565

But I can't figure out how to do it.


An example of how I do it:

mAnimationDrawable2 = (AnimationDrawable) animSearch.getDrawable();

Sam anim_search:

<animation-list xmlns:android=""
    <item android:drawable="@drawable/anim1_00001" android:duration="250" />
    <item android:drawable="@drawable/anim1_00002" android:duration="125" />

Tried doing this:

private void startFrameAnimation() {

        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        o = new BitmapFactory.Options();
        o.inPreferredConfig = Bitmap.Config.RGB_565;

        Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.anim1_00001, o);
        Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.anim1_00002, o);
        Bitmap bitmap3 = BitmapFactory.decodeResource(getResources(), R.drawable.anim1_00003, o);


        mAnimationDrawable2 = new AnimationDrawable();

        mAnimationDrawable2.addFrame(new BitmapDrawable(getResources(), bitmap1), 250);
        mAnimationDrawable2.addFrame(new BitmapDrawable(getResources(), bitmap2), 125);
        mAnimationDrawable2.addFrame(new BitmapDrawable(getResources(), bitmap3), 125);




        if (!mAnimationDrawable2.isRunning()) {
            mAnimationDrawable2.setVisible(true, true);

But it didn't really help, 37 frames, each weighing 30 kb. size 340 by 240 approximately, occupies about 120 megabytes in memory. Frames do not have an alpha channel.


It's hard to help solve a problem without seeing the code. Try to attach at least what is, so that people are more clear in which particular moment you are having difficulties.

Based on the information you provided in the question, here is the code that converts ARGB_8888 to RGB_565.

protected void onCreate(Bundle savedInstanceState){

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Config.RGB_565;
BitmapDrawable highScoresBg = BitmapFactory.decodeResource(getResources(), R.drawable.achievements, opts);
Scroll to Top