public Bitmap getScreenCap() throws IOException, InterruptedException {
byte[] tempBuffer = new byte[100 * 1024 * 1024];
StringBuilder buffer = new StringBuilder(100 * 1024 * 1024);
Process exec = Runtime.getRuntime().exec("su -c /system/bin/screencap -p");
final InputStream inputStream = exec.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
buffer.setLength(0);
int count;
while ((count = bufferedInputStream.read(tempBuffer)) > 0) {
buffer.append(new String(tempBuffer, 0, count, StandardCharsets.ISO_8859_1));
}
bufferedInputStream.close();
final int retCode = exec.waitFor();
exec.destroy();
tempBuffer = buffer.toString().getBytes(StandardCharsets.ISO_8859_1);
Bitmap stitchBmp = Bitmap.createBitmap(3120, 1440, Bitmap.Config.ARGB_8888);
stitchBmp.copyPixelsFromBuffer(ByteBuffer.wrap(tempBuffer));
return stitchBmp;
}
这是我的代码。我在Android P系统上。我总是会收到此错误。
java.lang.RuntimeException:缓冲区不足以容纳像素
如何修改缓冲区大小?