android屏幕截图

时间:2012-12-11 15:00:19

标签: java android video surfaceview android-videoview

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

        }
    }
}

1 个答案:

答案 0 :(得分:0)

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

Screen Capture in android

还有一个:

Programmatic screencapture on mobile device