Android将图像序列转换为视频生成" java.lang.IllegalStateException:无法在循环位图上调用getPixels()"错误

时间:2015-01-20 09:45:11

标签: android video android-bitmap

您好我正在创建一个Android应用程序,捕获屏幕截图的序列,然后将其转换为视频。我在捕获屏幕截图方面没有任何问题。我将这些屏幕截图保存在Bitmap数组中。将位图图像转换为视频时,我遇到java.lang.IllegalStateException: Can't call getPixels() on a recycled bitmap错误。

这是我的代码

public void convertToVideo(){
    File file = new File(Environment.getExternalStorageDirectory()+"/a.mp4");
    SequenceEncoder encoder;
    try {
        encoder = new SequenceEncoder(file);
        for (int i = 0; i < savedImagesPaths.size(); i++) {
            Bitmap bitmap = bitmapScreenShots.get(i);
            pic = BitmapUtil.fromBitmap(bitmap);
            for(int j=0;j<24;j++){
                encoder.encodeNativeFrame(pic);
            }
        }

        encoder.finish();
    } catch (IOException e) {
        System.out.println("Error Creating Video - "+e.getMessage());
        e.printStackTrace();
    }
}

但是当我尝试从外部路径拍摄图像并解码为位图时,会创建视频。

String photoPath = Environment.getExternalStorageDirectory()+"/Pictures/1419673564585.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(photoPath);

我不想从外部路径拍摄图像,我想将图像保存在位图数组中并使用它。

我该如何解决这个问题?

这是我的logcat

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)

0 个答案:

没有答案