Last active
November 7, 2022 08:16
-
-
Save tqk2811/a6a5e02486674bc7d0a96bba49f6b3af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class AdbHelper | |
{ | |
public static string AdbPath = "adb.exe"; | |
public static MemoryStream ExecuteCommandBuffer(string command) | |
{ | |
using(Process process = new Process()) | |
{ | |
process.StartInfo.FileName = AdbPath; | |
process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory(); | |
process.StartInfo.Arguments = command; | |
process.StartInfo.CreateNoWindow = true; | |
process.StartInfo.UseShellExecute = false; | |
process.StartInfo.RedirectStandardOutput = true; | |
process.StartInfo.RedirectStandardError = true; | |
process.StartInfo.RedirectStandardInput = true; | |
process.Start(); | |
MemoryStream memoryStream = new MemoryStream(); | |
process.StandardOutput.BaseStream.CopyTo(memoryStream); | |
process.WaitForExit(); | |
returrn memoryStream; | |
} | |
} | |
public static Bitmap ScreenShot(string deviceId) | |
{ | |
string args = $"-s {DeviceId} exec-out screencap -p"; | |
var stream = ExecuteCommandBuffer(args); | |
return (Bitmap)Bitmap.FromStream(stream); | |
} | |
public static void Main() | |
{ | |
using(Bitmap bitmap = ScreenShot("deviceId")) | |
{ | |
bitmap.Save("D:\\test.png"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment