Android AnimationDrawable Frame Compression

Question:

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.

UPD:

An example of how I do it:

animSearch.setImageResource(R.drawable.anim_search);
mAnimationDrawable2 = (AnimationDrawable) animSearch.getDrawable();
mAnimationDrawable2.start();

Sam anim_search:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/anim1_00001" android:duration="250" />
    <item android:drawable="@drawable/anim1_00002" android:duration="125" />
    .....
</animation-list> 

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);

.....

        mAnimationDrawable2.setOneShot(false);

        animSearch.setBackground(mAnimationDrawable2);

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

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.

Answer:

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){

setContentView(R.layout.high_scores);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Config.RGB_565;
BitmapDrawable highScoresBg = BitmapFactory.decodeResource(getResources(), R.drawable.achievements, opts);
findViewById(R.id.high_scores_root).setBackgroundDrawable(highScoresBg);
Scroll to Top