1

我想将视频屏幕捕获为来自 android 中的 videoview 的图像。下面给出了我的代码。它创建了图像,但该图像在 sdcard 中仅包含黑屏。如何在播放时将 videoview 捕获为图像。

public class VidePlayerActivity extends Activity {
/** Called when the activity is first created. */
public String fname;
public int n=1;
LinearLayout screen;
Timer timer;
Bitmap bmScreen;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);
    Button sr=(Button)findViewById(R.id.screenrec);
    screen=(LinearLayout)findViewById(R.id.screen);
    VideoView videoView=(VideoView)findViewById(R.id.videoView1);
    videoView.setVideoPath("sdcard/test.mp4");
    MediaController mediaController=new MediaController(this);
    videoView.setMediaController(mediaController);
    sr.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                    screen.setDrawingCacheEnabled(true);
                    bmScreen = screen.getDrawingCache();
                    saveImage(bmScreen);
        }
    });
    }
 protected void saveImage(Bitmap bmpscreen3) {

        //Toast.makeText(ScreenCaptureActivity.this, "saved", Toast.LENGTH_SHORT).show();
        File myDir=new File("/sdcard/Video_images");
          myDir.mkdirs();

           fname = "img"+ n +".jpg";
          File file = new File (myDir, fname);

        try {
            FileOutputStream ostream = new FileOutputStream(file);
            bmpscreen3.compress(CompressFormat.JPEG, 100, ostream);
            ostream.flush();
            ostream.close();
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}
4

1 回答 1

0

类似的东西已经发布到stackoverflow,下面的检查可能会帮助你。

安卓屏幕截图

这里还有一个:

移动设备上的程序化截屏

于 2012-12-11T15:17:44.230 回答