我想将视频屏幕捕获为来自 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();
}
}
}