public ADBHelper()
        {
            timer = new HiPerfTimer();
            //https://msdn.microsoft.com/zh-cn/library/system.diagnostics.process.beginoutputreadline(v=vs.110).aspx
            //http://blog.csdn.net/hcj116/article/details/7772262

            /*
             * CmdProcess = new Process();
             * CmdProcess.StartInfo.FileName = "cmd.exe";           //启动cmd
             * CmdProcess.StartInfo.UseShellExecute = false;        //自定义shell
             * CmdProcess.StartInfo.RedirectStandardInput = true;   //重定向标准输入
             * CmdProcess.StartInfo.RedirectStandardOutput = true;  //重定向标准输出
             * CmdProcess.StartInfo.RedirectStandardError = true;   //重定向错误输出
             * CmdProcess.StartInfo.CreateNoWindow = true;          //不显示原始窗口
             * CmdProcess.OutputDataReceived += CmdProcess_ProcessOutDataReceived;
             * CmdProcess.ErrorDataReceived += CmdProcess_ErrorDataReceived;
             * CmdProcess.Start();
             * cmdinput = CmdProcess.StandardInput;                 //重定向输入
             * CmdProcess.BeginOutputReadLine();                    //开始读取输出信息。这是个关键的步骤,否则不触发任何输出事件
             * CmdProcess.BeginErrorReadLine();
             * //CmdProcess.WaitForExit();
             */
        }
Пример #2
0
 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();
                 }
             }
         }));
     }
 }
Пример #3
0
 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();
                 }
             }
         }));
     }
 }