0

スクリーンショットを撮ってギャラリーに保存するコードは次のとおりです。ここでデバッグしてみました画面はキャプチャされますが、ギャラリーには保存されません。

@Override
            public void onClick(View v) {
                Bitmap bitmap = takeScreenshot();
                saveBitmap(bitmap);
            }

スクリーンショットの作成

protected Bitmap takeScreenshot() {
    // TODO Auto-generated method stub
    View rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
    Toast.makeText(getApplicationContext(), "Screen captured", Toast.LENGTH_LONG).show();
    return rootView.getDrawingCache();

}

保存画面はこちら

 protected void saveBitmap(Bitmap bitmap) {
            // TODO Auto-generated method stub
            File imagePath = new File(Environment.getExternalStorageDirectory()
                    + "/screenshot.png");

            FileOutputStream fos;
            try {
                fos = new FileOutputStream(imagePath);
                bitmap.compress(CompressFormat.JPEG, 100, fos);
                fos.flush();
                fos.close();
                Toast.makeText(getApplicationContext(), "Screen saved", Toast.LENGTH_LONG).show();
            } catch (FileNotFoundException e) {
                Log.e("GREC", e.getMessage(), e);
            } catch (IOException e) {
                Log.e("GREC", e.getMessage(), e);
            }
        }
4

1 に答える 1

0

デバイスでコードを実行してください。エミュレータには物理的な SD カードがないため、エミュレータの問題である可能性があります。

于 2013-09-16T10:31:16.170 に答える