我想将视频屏幕视为来自androidview中的videoview的图像。我的代码如下所示。创建图像但该图像仅包含sdcard.how中的黑屏,以便在播放时将视频视图捕获为图像。
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();
}
}
}
答案 0 :(得分:0)
类似的东西已经发布到stackoverflow,下面的检查可能会帮助你。
还有一个: