1
我想捕獲視頻屏幕作爲android..my代碼中的videoview中的圖像給出如下。它創建圖像,但該圖像僅包含sdcard.how中的黑屏以在播放時捕獲視頻圖像作爲圖像。android屏幕截圖
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();
}
}
}