Пример #1
0
        private int ElementScreenshot(string ImageName, string ImageElementID, string PathToTheImage)
        {
            int result = 0;
            try
            {
                ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
                Screenshot screenshot = screenshotDriver.GetScreenshot();
                screenshot.SaveAsFile("Screen.png", ImageFormat.Png);

                //координаты и поинтер искомого имеджа

                IWebElement TargetImage = driver.FindElement(By.Id(ImageElementID)).FindElement(By.XPath(PathToTheImage));
                int width = TargetImage.Size.Width;
                int height = TargetImage.Size.Height;
                Point ElemPoint = TargetImage.Location;

                //исходный имедж
                Bitmap sourceBitmap = new Bitmap("Screen.png");
                //скрин компонента
                Bitmap PartOfScrn = new Bitmap(width - 1, height);

                Color sourceColor = new Color();

                for (int i = 0; i < width - 1; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        sourceColor = sourceBitmap.GetPixel(i + ElemPoint.X, j + ElemPoint.Y);
                        PartOfScrn.SetPixel(i, j, sourceColor);
                    }
                }
                PartOfScrn.Save(ImageName + ".png");

                //var sFile = new FileStream(@"C:\" + PicName + ".png", FileMode.Open);
                var sFile = new FileStream(ImageName + ".png", FileMode.Open);
                byte[] PhotoBytes = new byte[sFile.Length];
                sFile.Read(PhotoBytes, 0, PhotoBytes.Length);
                Simple_Bot.ocr.ocrSoapClient webservice = new Simple_Bot.ocr.ocrSoapClient();
                //SimpleBotLibrary.ocr.ocrSoapClient webservice = new SimpleBotLibrary.ocr.ocrSoapClient();
                result = Convert.ToInt32(webservice.Analyze("*****@*****.**", PhotoBytes));

                sFile.Dispose();
                PartOfScrn.Dispose();
                sourceBitmap.Dispose();
            }
            catch { }

            return result;
        }
Пример #2
0
        private int ElementScreenshot(string ImageName, string ImageElementID, string PathToTheImage)
        {
            int result = 0;
            try
            {
                //Пытаемся сделать скрин или выводим сообщение что нужно мешать в ручную
                if (StirringGetScreenshot())
                {

                    //координаты и поинтер искомого имеджа
                    IWebElement TargetImage = driver.FindElement(By.Id(ImageElementID)).FindElement(By.XPath(PathToTheImage));

                    //фокусимся на кнопке Помешать, чтоб сдвинуть немножко скрин
                    Actions action = new Actions(driver);
                    action.MoveToElement(driver.FindElement(By.XPath("//input[@value='ПОМЕШАТЬ']"))).Build().Perform();
                    int width = TargetImage.Size.Width;
                    int height = TargetImage.Size.Height;
                    Point ElemPoint = TargetImage.Location;

                    //исходный имедж
                    Bitmap sourceBitmap = new Bitmap("Screen.png");
                    //скрин компонента
                    Bitmap PartOfScrn = new Bitmap(width - 1, height);

                    Color sourceColor = new Color();

                    for (int i = 0; i < width - 1; i++)
                    {
                        for (int j = 0; j < height; j++)
                        {
                            sourceColor = sourceBitmap.GetPixel(i + ElemPoint.X, j + ElemPoint.Y);
                            PartOfScrn.SetPixel(i, j, sourceColor);
                        }
                    }
                    PartOfScrn.Save(ImageName + ".png");

                    var sFile = new FileStream(ImageName + ".png", FileMode.Open);
                    byte[] PhotoBytes = new byte[sFile.Length];
                    sFile.Read(PhotoBytes, 0, PhotoBytes.Length);
                    Simple_Bot.ocr.ocrSoapClient webservice = new Simple_Bot.ocr.ocrSoapClient();
                    //SimpleBotLibrary.ocr.ocrSoapClient webservice = new SimpleBotLibrary.ocr.ocrSoapClient();
                    result = Convert.ToInt32(webservice.Analyze("*****@*****.**", PhotoBytes));

                    sFile.Dispose();
                    PartOfScrn.Dispose();
                    sourceBitmap.Dispose();
                }
                else
                {
                    MessageBox.Show("Нужно уровнять температуру в котле!", "Simpe Bot: Information",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SoundPlayer simpleSound = new SoundPlayer(Resource.Stirring_Sound);
                    simpleSound.Play();
                }
            }
            catch { }

            if (result == 0)
            {
                MessageBox.Show("Нужно уровнять температуру в котле!", "Simpe Bot: Information",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                SoundPlayer simpleSound = new SoundPlayer(Resource.Stirring_Sound);
                simpleSound.Play();
            }

            return result;
        }