开发者

screen shot for the activity

i want to create a bitmap of whats being currently displayed of my app, one thing i went into is cant read FB buffer requires root, would like to know if it is possible to create a image file for the screen, please i want the help to code this, no 3rd party intents , thanks, answers w开发者_StackOverflowould be much appreciated


From your Activity (pseudo-code):

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


You can use FFMPEG to capture the Screen


Try this.....

{
    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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜