1

アプリのスクリーンショットを保存しようとしています。私のメイン画面はSurfaceViewです。新しいキャンバスを作成し、サーフェスビューをキャンバスに描画しています。取得したPNGが完全に透明であるため、問題があります。

これが私のコードです

Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(image);
    draw(c);

    String path=Environment.getExternalStorageDirectory() + "/test2.png";
    File file = new File(path);
    try 
    {
        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        image.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
        Uri screenshotUri = Uri.parse("file://"+file.getAbsolutePath());
        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.setDataAndType(screenshotUri, "image/png");
       startActivity(sendIntent);
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
4

1 に答える 1