2011-06-21 4 views
0

私はアンドロイドに取り組んでいます。スクリーンショットをキャプチャする次のコードがあります。あなたのルートのレイアウトを設定するスクリーンショットは空白です:アンドロイド?

:私の問題は、それがゼロキロバイトのファイルを作成することです

private void getScreen() 
{ 
    View content = findViewById(R.id.layoutroot); 
    Bitmap bitmap = content.getDrawingCache(); 
    File file = new File("/sdcard/test.png"); 
    try 
    { 
     file.createNewFile(); 
     FileOutputStream ostream = new FileOutputStream(file); 
     bitmap.compress(CompressFormat.PNG, 100, ostream); 
     ostream.close(); 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 
} 

View content = findViewById(R.id.layoutroot); 
content.setDrawingCacheEnabled(true); 

機能レンダリングされたビューを取得します。何が問題なの?

答えて

0

これらの変更を行い、再度実行してください:

  • を、最終的なコンテンツの変数を作成し、活動のレイアウト

    最終の表示内容= somelayout.findViewById(R.id.layoutrootにfindViewByIdを呼び出します);

0

あなたはファイルにデータを書き込んでいません。あなたは

使用何かこの

try 
    { 
     file.createNewFile(); 
     FileOutputStream ostream = new FileOutputStream(file); 
     byte[] mydata = null;//data in byte array 
     ostream.write(mydata); 
     ostream.close(); 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 
のような0キロバイトのファイルを持っなぜあなたは直接、ファイルのthatsを閉じています
関連する問題