应用内截屏

今天实现了在应用内截屏的方法,很简单代码如下:

(有surfaceView不能截取)

 

private boolean shot(){
    Bitmap bm = Bitmap.createBitmap(480, 854, Config.ARGB_8888);
    Canvas canvas = new Canvas(bm);
    getWindow().getDecorView().draw(canvas);
    if (Environment.getExternalStorageState().equals(
            Environment.MEDIA_MOUNTED)) {
        File file = new File("/sdcard/tt/tt.png");
        try {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
                file.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(file);
            bm.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
关于SurfaceView的截取,在surfaceView中使用双缓冲,可以截取,但貌似效率会变低,谁有好的解决方法,麻烦告诉我,谢谢~
 
posted @ 2011-11-23 10:25  ihou  阅读(392)  评论(0编辑  收藏  举报