Beispiel #1
0
        private void Initialize()
        {
            const string KEY_CROP_FILENAME = "key.lvb";
            const int KEY_CROP_X = 250, KEY_CROP_Y = 473, KEY_CROP_WIDTH = 524, KEY_CROP_HEIGHT = 58;
            const string BAR_CROP_FILENAME = "bar.lvb";
            const int BAR_CROP_X = 254, BAR_CROP_Y = 518, BAR_CROP_WIDTH = 524, BAR_CROP_HEIGHT = 43;

            windowFinder = new WindowFinder();
            imageFinder = new ImageFinder(0.9);

            // load all images based on Signal types. throws error if any of these are not found
            foreach (Signal s in Enum.GetValues(typeof(Signal)))
            {
                string subImagePath = String.Format("{0}{1}{2}", IMAGE_PATH, s.ToString(), IMAGE_EXT);
                imageFinder.SubImages.Add(s, new Image<Bgr, byte>(subImagePath));
            }

            // init gamestate
            for (int i = 0; i < gameState.Length; i++)
            {
                gameState[i] = new Signal[KEY_COLUMNS_MAX];
            }

            keyCropSettings = CropSettings.Load(KEY_CROP_FILENAME, KEY_CROP_X, KEY_CROP_Y, KEY_CROP_WIDTH, KEY_CROP_HEIGHT);
            keyCropSettings.SaveIfNotExist(KEY_CROP_FILENAME);

            barCropSettings = CropSettings.Load(BAR_CROP_FILENAME, BAR_CROP_X, BAR_CROP_Y, BAR_CROP_WIDTH, BAR_CROP_HEIGHT);
            barCropSettings.SaveIfNotExist(BAR_CROP_FILENAME);
        }
Beispiel #2
0
        private Image<Bgr, byte> getCroppedScreenshot(CropSettings cs)
        {
            try
            {
                // TODO: determine crop height on the fly
                Image<Bgr, byte> convertedScreenshot;
                using (Bitmap screenshot = windowFinder.GetScreenshot(true,
                    new Rectangle(cs.X, cs.Y, cs.Width, cs.Height)))
                {
                    convertedScreenshot = new Image<Bgr, byte>(screenshot);
                }

                return convertedScreenshot;
            }
            catch (Exception)
            {
                return null;
            }
        }