如何在画布中记录用户的操作并在android中保存为视频文件?

时间:2012-06-01 05:08:02

标签: android video canvas

我已经实现了绘画功能。 我想记录用户的操作并保存为视频文件。 就像IPAD中的“SHOW ME”应用程序一样。 我怎么能这样做?

1 个答案:

答案 0 :(得分:-1)

您可以使用以下代码截取您自己的应用程序的屏幕截图(根据您的应用进行一些修改):

public class AndroidWebImage extends Activity {

ImageView bmImage; 
LinearLayout view;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      view = (LinearLayout)findViewById(R.id.screen);
      bmImage = (ImageView)findViewById(R.id.image);

      view.setDrawingCacheEnabled(true);
      // this is the important code :)  
      // Without it the view will have a dimension of 0,0 and the bitmap will be null          

      view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

      view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 

      view.buildDrawingCache(true);
      Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
      view.setDrawingCacheEnabled(false); // clear drawing cache

      bmImage.setImageBitmap(b);   

};


}

我使用了以下xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
   android:id="@+id/screen"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/hello"
  />
<ImageView
  android:id="@+id/image"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
/>
</LinearLayout>

使用定时器按固定时间间隔截取屏幕截图,然后将此系列图像转换为视频文件,如:create-a-video-file-from-images-using-ffmpeg