private void runADBShell(string shellcommand) { CmdStatus = OutputStatus.Busy; OutputData = string.Empty; bytesOutputfixed = null; timer.Start(); bytesOutputfixed = Fix0d0d0a(RunAdbProcess(shellcommand)); timer.Stop(); OutputData = System.Text.Encoding.ASCII.GetString(bytesOutputfixed).Replace((char)0x0a, ' '); if (shellcommand.Contains("shell screencap -p") || shellcommand.Contains("shell dumpsys window")) { //System.IO.File.WriteAllBytes(@"D:\1fix.png", bytesOutputfixed); OutputText = shellcommand + " (received " + bytesOutputfixed.Length.ToString() + ") "; } else { if (string.IsNullOrEmpty(OutputData)) { OutputText = shellcommand + " "; } else { OutputText = OutputData.Replace("\r", ""); } } if (shellcommand.Contains("getprop") && string.IsNullOrEmpty(OutputData)) { OutputText = "no devices"; } if (Output != null) { Output(null, new EventArgsOutput() { Output = OutputText + "--> " + timer.Duration.ToString() + "\r\n" }); } CmdStatus = OutputStatus.Success; }
private void CaptureAndriod() { //截屏获取图片 ADB.RunADBShellCommand("shell screencap -p"); if (ADB.bytesOutputfixed != null) { using (MemoryStream pngStream = new MemoryStream(ADB.bytesOutputfixed)) { HiPerfTimer timer = new HiPerfTimer(); timer.Start(); Bitmap bmpfix = null; try { bmpfix = DetectStartPoint(pngStream); } catch (Exception ex) { Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText(ex.ToString()); rtbCmd.ScrollToCaret(); } } })); } timer.Stop(); if (bmpfix != null) { string tmp = "Detect:" + timer.Duration.ToString() + "\r\n"; Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText(tmp); rtbCmd.ScrollToCaret(); } } })); pictureBox1.Invoke(new Action(() => { pictureBox1.Image = bmpfix; pictureBox1.Refresh(); })); } else { Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText("bmpfix is null!"); rtbCmd.ScrollToCaret(); } } })); } } } else { Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText("bytesOutputfixed is null!"); rtbCmd.ScrollToCaret(); } } })); } }
private void CaptureAndriod() { //截屏获取图片 ADB.RunADBShellCommand("shell screencap -p"); if (ADB.bytesOutputfixed != null) { using (MemoryStream pngStream = new MemoryStream(ADB.bytesOutputfixed)) { HiPerfTimer timer = new HiPerfTimer(); timer.Start(); Bitmap bmpfix = null; try { bmpfix = DetectStartPoint(pngStream); //为什么有的手机截屏画面上下颠倒呢??? if (cbxRotate180.Checked) { bmpfix.RotateFlip(RotateFlipType.Rotate180FlipNone); } using (Graphics g = Graphics.FromImage(bmpfix)) { using (Font font = new Font("Times New Roman", 36)) { string xyText = "(" + StartX.ToString() + "," + StartY.ToString() + ")"; g.DrawString(xyText, font, Brushes.Red, new PointF(10, 30)); } } } catch (Exception ex) { Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText(ex.ToString()); rtbCmd.ScrollToCaret(); } } })); } timer.Stop(); if (bmpfix != null) { string tmp = "Detect:" + timer.Duration.ToString() + "\r\n"; Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText(tmp); rtbCmd.ScrollToCaret(); } } })); pictureBox1.Invoke(new Action(() => { pictureBox1.Image = bmpfix; pictureBox1.Refresh(); })); } else { Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText("bmpfix is null!"); rtbCmd.ScrollToCaret(); } } })); } } } else { Invoke(new MethodInvoker(delegate() { { if (rtbCmd != null) { rtbCmd.AppendText("bytesOutputfixed is null!"); rtbCmd.ScrollToCaret(); } } })); } }