0

As I mentioned in the title, I wanted to creating the gif using the codes below, but I got an error.

ArrayList<Bitmap> bitmaps = bitmapss;
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                AnimatedGifEncoder encoder = new AnimatedGifEncoder();
                encoder.setDelay(500);
                encoder.setRepeat(0);
                encoder.start(bos);
                for (Bitmap bitmap : bitmaps) {
                    encoder.addFrame(bitmap);
                }

                encoder.finish();

                File filePath = new File("/sdcard", "sample.gif");
                FileOutputStream outputStream;
                try {
                    outputStream = new FileOutputStream(filePath);
                    outputStream.write(bos.toByteArray());
                } catch (FileNotFoundException e) {
                } catch (IOException e) {
                }
            }

Error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.deneme, PID: 13712
    java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@c5215a7
      
  • [This](https://stackoverflow.com/questions/22129420/canvas-trying-to-use-a-recycled-bitmap-android-graphics-bitmap-in-android/27420377#27420377) may also help you. – fuggerjaki61 Feb 19 '21 at 07:54
  • https://stackoverflow.com/questions/22129420/canvas-trying-to-use-a-recycled-bitmap-android-graphics-bitmap-in-android – Usama Altaf Feb 19 '21 at 07:54
  • @UsamaAltaf I couldn't make the solution compatible with my code. Can you write me the solution in code? –  Feb 19 '21 at 11:15

0 Answers0