开发者

android how to take screen shot programmatically when in surfaceview

I don't use xml here and getroot() doesn't work for me. I saw Store Bitmap Screenshot in Android Cache but I don't know how he got the mCurrentUrlMask referrence.

my code is:

View v= getRootView();
v.setDrawingCacheEnabled(true);
// this is the important code :)  
// Without it the view will have a dimension of 0,0 and the bitmap will be null          
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, getMeasuredWidth(), getMeasuredHeight()); 

v.buildDrawingCache(true);
Bitmap bitmap =v.getDrawingCache();
path=Environment.getExternalStorageDirectory() + "/test.png";
File file = new Fil开发者_JS百科e(path);
try 
{
    file.createNewFile();
    FileOutputStream ostream = new                     FileOutputStream(file);
    bitmap.compress(CompressFormat.PNG, 100, ostream);
    ostream.close();
} 
catch (Exception e) 
{
    e.printStackTrace();
}

and I get an ioexception permission deniened while working on the emulator and uses the external-storage permission.(the code works well on a test application while using xml and findviewbyid but in this application I can't use it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜