Esempio n. 1
0
        /// <summary>
        /// Cuts the images on slices.
        /// </summary>
        /// <param name="pathIn">The path in.</param>
        /// <param name="pathOut">The path out.</param>
        public void CutImagesOnSlices(string pathIn, string pathOut)
        {
            int counter = 0;

            foreach (string fileName in Directory.GetFiles(@pathIn))
            {
                var image = new BitmapImage(new Uri(fileName, UriKind.RelativeOrAbsolute));

                for (int i = 0; i < image.Height - Constants.HEIGHT; i += Constants.HEIGHT)
                {
                    for (int j = 0; j < image.Width - Constants.WIDTH; j += Constants.WIDTH)
                    {
                        try
                        {
                            var pieceOfImage = new CroppedBitmap(image, new Int32Rect(j, i, Constants.WIDTH, Constants.HEIGHT));
                            pieceOfImage.SaveImage($"{pathOut}\\{counter}.png");
                            counter++;
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
            }
        }