android应用程序截图明确布局

android应用程序截图明确布局,android,layout,screenshot,Android,Layout,Screenshot,安卓应用程序截图明确布局,我有问题,截图后,图像是黑色的例外图像,在布局上 这是我的密码 真实截图: 我的代码截图: 请尝试以下代码: private Bitmap getscreenshot() { SimpleDateFormat date= new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss").format(new Date()); try { String mPath = Environment.g

安卓应用程序截图明确布局,我有问题,截图后,图像是黑色的例外图像,在布局上

这是我的密码

真实截图:

我的代码截图:

请尝试以下代码:

 private Bitmap getscreenshot() {

    SimpleDateFormat date= new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss").format(new Date());
        try {

            String mPath = Environment.getExternalStorageDirectory().toString() + "/" + date+ ".jpg";

            // create bitmap screen capture
            View v1 = getWindow().getDecorView().getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);

            File imageFile = new File(mPath);

            FileOutputStream outputStream = new FileOutputStream(imageFile);
            int quality = 100;
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
            outputStream.flush();
            outputStream.close();

          return bitmap;
        } catch (Throwable e) {

            e.printStackTrace();
        }
    return null;
}
请尝试以下代码:

 private Bitmap getscreenshot() {

    SimpleDateFormat date= new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss").format(new Date());
        try {

            String mPath = Environment.getExternalStorageDirectory().toString() + "/" + date+ ".jpg";

            // create bitmap screen capture
            View v1 = getWindow().getDecorView().getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);

            File imageFile = new File(mPath);

            FileOutputStream outputStream = new FileOutputStream(imageFile);
            int quality = 100;
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
            outputStream.flush();
            outputStream.close();

          return bitmap;
        } catch (Throwable e) {

            e.printStackTrace();
        }
    return null;
}
我只想截图“截图布局”布局


我只想截图“截图布局”布局


<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/mylayout">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/sual_imagebox"/>
       <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/screenshotlayout">
            <io.github.kexanie.library.MathView
                android:id="@+id/sual"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                auto:text="text"
                auto:engine="MathJax"
                android:layout_below="@+id/bookmark">
            </io.github.kexanie.library.MathView>
        </LinearLayout>
  </RelativeLayout>