Skip to content

Instantly share code, notes, and snippets.

@tqk2811
Last active November 7, 2022 08:16
Show Gist options
  • Save tqk2811/a6a5e02486674bc7d0a96bba49f6b3af to your computer and use it in GitHub Desktop.
Save tqk2811/a6a5e02486674bc7d0a96bba49f6b3af to your computer and use it in GitHub Desktop.
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