屏幕截图为活动

时间:2010-07-15 10:34:09

标签: android

我想创建一个当前显示我的应用程序的位图,我进入的一件事是无法读取FB缓冲区需要root,想知道是否有可能为屏幕创建图像文件,请我希望帮助对此进行编码,没有第三方意图,谢谢,答案将不胜感激

3 个答案:

答案 0 :(得分:0)

来自您的活动(伪代码):

Bitmap bm = Bitmap.create...
Canvas canvas = new Canvas(bm);
getWindow.getDecorView().draw(canvas);

答案 1 :(得分:0)

您可以使用FFMPEG捕获屏幕

答案 2 :(得分:0)

试试这个......

{
    LinearLayout view = (LinearLayout) findViewById(R.id.imageLayout);
    View v1 = view.getRootView();
    v1.setDrawingCacheEnabled(true);
    String dir="myimages";
    Bitmap bm = v1.getDrawingCache();        
    saveBitmap(bm, dir, "capturedimage");
}
static String saveBitmap(Bitmap bitmap, String dir, String baseName) {
    try {
        File sdcard = Environment.getExternalStorageDirectory();
        File pictureDir = new File(sdcard, dir);
        pictureDir.mkdirs();
        File f = null;
        for (int i = 1; i < 200; ++i) {
            String name = baseName + i + ".png";    
            f = new File(pictureDir, name);
            if (!f.exists()) {
                break;
            }
        }
        System.out.println("Image size : "+bitmap.getHeight());
        if (!f.exists()) {
            String name = f.getAbsolutePath();
            FileOutputStream fos = new FileOutputStream(name);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            System.out.println("After File Size : "+f.length());
            fos.flush();
            fos.close();

            return name;
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Exception in saveBitmap: "+e.getMessage());
    } finally {

    }
    return null;
}