在Android的屏幕捕获 [英] Screen Capture in android

查看:103
本文介绍了在Android的屏幕捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个应用程序,将采取截图的Andr​​oid screen..does中的任何一个知道怎么做..?这是类似koushik duttas屏幕shot..But使用root..and没有任何一个有koushik杜塔截屏的应用程序,正在抓紧研究制定..?不工作的me..please让我know..thanks提前。

I want to develop an application that will take screenshot of android screen..does any one know how to do it..? which is similar to koushik duttas screen shot..But with out using root..and does any one had koushik dutta screenshot application which is working..? is not working for me..please let me know..thanks in advance.

推荐答案

让我们说你点击一个按钮:

Let's say that you clicked on a button:

findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
       Bitmap bitmap = takeScreenshot();
       saveBitmap(bitmap);
   }
});

在您需要这两种方法:

public Bitmap takeScreenshot() {
   View rootView = findViewById(android.R.id.content).getRootView();
   rootView.setDrawingCacheEnabled(true);
   return rootView.getDrawingCache();
}

 public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

这篇关于在Android的屏幕捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆