You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello,In Java I take a screenshot of the device with the following adb command, and when I convert the stream to an image, I get an incorrect image, the code looks like this:
String command = String.format("adb shell CLASSPATH=/data/local/tmp/minicap-devel/minicap-debug.apk app_process /system/bin io.devicefarmer.minicap.Main -P %s@%s/0 -s", screenSize, screenSize);
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
BufferedInputStream bis = new BufferedInputStream(inputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = bis.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, bytesRead);
}
byte[] imageBytes = byteArrayOutputStream.toByteArray();
InputStream byteArrayInputStream = new ByteArrayInputStream(imageBytes);
BufferedImage bufferedImage = ImageIO.read(byteArrayInputStream);
if (bufferedImage == null) {
throw new IOException("Failed to decode image from input stream.");
}
File outFile = new File(savePath);
ImageIO.write(bufferedImage, "jpg", outFile);
the image looks like this:
However, when I modify the source code of the minicap-debug.apk, the Screenshot Output sent to the screenshot stream is changed here to look like this:
class ScreenshotOutput(private val output: PrintStream) : DisplayOutput() {
override fun send() {
val writer = PrintWriter(output)
writer.use {
val encodedImage: String = Base64.encodeToString(imageBuffer.toByteArray(), Base64.DEFAULT)
it.write(encodedImage)
it.flush()
}
}
}
On the java side, the screenshot stream is decoded in Base 64 and then converted to obtain the correct image,java changed here to look like this:
String command = String.format("adb shell CLASSPATH=/data/local/tmp/minicap-devel/minicap-debug.apk app_process /system/bin io.devicefarmer.minicap.Main -P %s@%s/0 -s", screenSize, screenSize);
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
reader.close();
// Decode the Base64 string to byte array
byte[] imageBytes = Base64.getDecoder().decode(stringBuilder.toString());
// Convert byte array to BufferedImage
InputStream byteArrayInputStream = new ByteArrayInputStream(imageBytes);
BufferedImage bufferedImage = ImageIO.read(byteArrayInputStream);
if (bufferedImage == null) {
throw new IOException("Failed to decode image from input stream.");
}
// Write the BufferedImage to file
File outFile = new File(savePath);
ImageIO.write(bufferedImage, "jpg", outFile);
The image I get after the modification is very correct, I want to know how to parse the image correctly when not using Base 64, thank you
The text was updated successfully, but these errors were encountered:
hello,In Java I take a screenshot of the device with the following adb command, and when I convert the stream to an image, I get an incorrect image, the code looks like this:
the image looks like this:
However, when I modify the source code of the minicap-debug.apk, the Screenshot Output sent to the screenshot stream is changed here to look like this:
On the java side, the screenshot stream is decoded in Base 64 and then converted to obtain the correct image,java changed here to look like this:
The image I get after the modification is very correct, I want to know how to parse the image correctly when not using Base 64, thank you
The text was updated successfully, but these errors were encountered: