public System.Drawing.Bitmap CaptureScreenshot()
        {
            var bytes  = AdbApi.CaptureScreenshot(AdbStream);
            var bitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(new System.IO.MemoryStream(bytes));

            bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
            return(bitmap);
        }
        public AdbClient(string device, int?adbPort = null)
        {
            this.Device  = device;
            this.AdbPort = adbPort ?? AdbPort_Default;

            this.TcpClient = new TcpClient("127.0.0.1", AdbPort);
            this.AdbStream = this.TcpClient.GetStream();

            AdbApi.RunCommand(AdbStream, $"host:transport:{Device}");
        }
Beispiel #3
0
        //https://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
        static byte[] AdbScreenCapture()
        {
            var command = "shell:screencap -p";

            var port = 5037;

            //var port = 5555;
            using (var client = new TcpClient("127.0.0.1", port))
            {
                using (var stream = client.GetStream())
                {
                    SendToAdb(stream, "host:transport:emulator-5554", isPayload: false);
                    //SendToAdb(stream, $"shell:{command}", isPayload: true);

                    var fullCommand = $"{command.Length:x4}{command}";
                    Console.WriteLine(fullCommand);
                    var buf = Encoding.UTF8.GetBytes(fullCommand);
                    stream.Write(buf, 0, buf.Length);
                    var okay = ReceiveFromAdb(stream, length: 4);
                    Console.WriteLine($">>{okay.Length} {okay}");
                    if (okay.Substring(0, 4) != "OKAY")
                    {
                        throw new Exception($"error adb receive: {okay}");
                    }

                    return(AdbApi.ReplaceDAToA(AdbApi.ReadAll(stream)));
                    //var prefix = ReceiveFromAdb(stream, 4);
                    //if (prefix.Length == 0)
                    //    return null;
                    //Console.WriteLine($">>{prefix.Length} {prefix}");
                    //var length = Convert.ToInt32(prefix);

                    //var answerBuf = new byte[length];
                    //int len = stream.Read(answerBuf, 0, answerBuf.Length);
                    //Console.WriteLine(len);

                    //return answerBuf;
                }
            }
        }
 public void Back()
 {
     AdbApi.Back(AdbStream);
 }
 public void Tap(int x, int y)
 {
     AdbApi.Tap(AdbStream, x, y);
 }