title: Android converting sequence of images to video generating "java.lang.IllegalStateException: Can't call getPixels() on a recycled bitmap" error
body: <p>Hi i am creating an android app that captures the sequence of screenshot and then converts it to the video. I don't have any problem on capturing screenshots. I am saving these screenshots in a Bitmap array. While converting the Bitmap images to video am getting the <code>java.lang.IllegalStateException: Can't call getPixels() on a recycled bitmap</code> error.</p>
  
  <p>Here is my code</p>
  
  <pre><code>public void convertToVideo(){
      File file = new File(Environment.getExternalStorageDirectory()+"/a.mp4");
      SequenceEncoder encoder;
      try {
          encoder = new SequenceEncoder(file);
          for (int i = 0; i &lt; savedImagesPaths.size(); i++) {
              Bitmap bitmap = bitmapScreenShots.get(i);
              pic = BitmapUtil.fromBitmap(bitmap);
              for(int j=0;j&lt;24;j++){
                  encoder.encodeNativeFrame(pic);
              }
          }
  
          encoder.finish();
      } catch (IOException e) {
          System.out.println("Error Creating Video - "+e.getMessage());
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>But when i am trying to take image from external path and decoded as a bitmap, the video is created.</p>
  
  <pre><code>String photoPath = Environment.getExternalStorageDirectory()+"/Pictures/1419673564585.jpg";
  Bitmap bitmap = BitmapFactory.decodeFile(photoPath);
  </code></pre>
  
  <p>i don't want to take images from external path, i want to save images in bitmap array and use it.</p>
  
  <p>How can i resolve this? </p>
  
  <p>Here is my logcat</p>
  
  <pre><code>01-20 14:52:02.334: E/AndroidRuntime(15211): FATAL EXCEPTION: main
  01-20 14:52:02.334: E/AndroidRuntime(15211): Process: com.example.drawingfun, PID: 15211
  01-20 14:52:02.334: E/AndroidRuntime(15211): java.lang.IllegalStateException: Can't call getPixels() on a recycled bitmap
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.graphics.Bitmap.checkRecycled(Bitmap.java:352)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.graphics.Bitmap.getPixels(Bitmap.java:1342)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at org.jcodec.scale.BitmapUtil.fromBitmap(BitmapUtil.java:31)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at org.jcodec.scale.BitmapUtil.fromBitmap(BitmapUtil.java:23)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at com.example.drawingfun.MainActivity.convertToVideo(MainActivity.java:295)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at com.example.drawingfun.MainActivity.onClick(MainActivity.java:247)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.view.View.performClick(View.java:4756)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.view.View$PerformClick.run(View.java:19749)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.os.Handler.handleCallback(Handler.java:739)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.os.Handler.dispatchMessage(Handler.java:95)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.os.Looper.loop(Looper.java:135)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at android.app.ActivityThread.main(ActivityThread.java:5221)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at java.lang.reflect.Method.invoke(Native Method)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at java.lang.reflect.Method.invoke(Method.java:372)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  01-20 14:52:02.334: E/AndroidRuntime(15211):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>