我试图将我的
以下是我用于获取
ScrollView
转换为 bitmap
,我的 ScrollView
的内容超出了屏幕(因此可以滚动),在 这里询问 后,我可以捕获 ScrollView
中的 Activity,但是我遇到了一个问题,用于保存屏幕截图的 Bitmap
只创建了最后一个 ScrollView
的视图,其余部分都是黑屏,如下所示:
![enter image description here](https://istack.dev59.com/1izCQ.webp)
ScrollView
中所有视图的代码: scroll_pp=(ScrollView)polis.findViewById(R.id.scroll_pp);
utktest=polis.findViewById(R.id.scroll_pp);
int totalHeight = scroll_pp.getChildAt(0).getHeight();
int totalWidth = scroll_pp.getChildAt(0).getWidth();
Bitmap b= MethodSupport.loadBitmapFromView(utktest, totalWidth, totalHeight);
String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "Folder";
String fileName = "Test.jpg";
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), b, "Screen", "screen");
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
public static Bitmap loadBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
那么,我的代码有什么问题,所以我无法按照想要的方式显示位图
吗?