Esempio n. 1
0
        private void Play_Click(object sender, RoutedEventArgs e)
        {
            Play.IsEnabled  = false;
            Check.IsEnabled = true;
            Auto.IsEnabled  = true;
            int fCount = Directory.GetFiles(searchFolder, "*.jpg", SearchOption.TopDirectoryOnly).Length;
            List <BitmapImage> bitmaps = new List <BitmapImage>();

            for (int i = 0; i < fCount; i++)
            {
                string img;
                if (i < 9)
                {
                    img = "img0" + (i + 1) + ".jpg";
                }
                else
                {
                    img = "img" + (i + 1) + ".jpg";
                }
                BitmapImage bitmap = new BitmapImage(new Uri(searchFolder + img));
                bitmaps.Add(bitmap);
            }

            Random rand = new Random();
            var    nums = Enumerable.Range(0, fCount).ToArray();

            for (int i = 0; i < nums.Length; ++i)
            {
                int randomIndex = rand.Next(nums.Length);
                int temp        = nums[randomIndex];
                nums[randomIndex] = nums[i];
                nums[i]           = temp;
            }
            ImageData[] images_r = new ImageData[fCount];
            for (int i = 0; i < fCount; i++)
            {
                images_r[nums[i]] = new ImageData {
                    Images = bitmaps[i]
                };
            }
            //this.SizeToContent = SizeToContent.Height;
            this.SizeToContent      = SizeToContent.Width;
            this.piccc2.Width       = 100 * w;
            this.piccc2.Height      = 100 * h;
            this.piccc2.ItemsSource = images_r;
            ImageData[] images2 = new ImageData[fCount];
            Bitmap      bmp     = new Bitmap(50, 50);

            using (Graphics graph = Graphics.FromImage(bmp))
            {
                System.Drawing.Rectangle ImageSize = new System.Drawing.Rectangle(0, 0, 50, 50);
                graph.FillRectangle(System.Drawing.Brushes.White, ImageSize);
            }
            //for (int i = 0; i < fCount; i++)
            //{
            //    imagesbitTotal[i] = bmp;
            //}
            for (int i = 0; i < fCount; i++)
            {
                images2[i] = new ImageData {
                    Images = Exten.ToBitmapImage(bmp)
                };
            }
            this.piccc3.Width       = 100 * w;
            this.piccc3.Height      = 100 * h;
            this.piccc3.ItemsSource = images2;
            for (int i = 0; i < fCount; i++)
            {
                imagesTotal[i] = (ImageData)piccc3.Items[i];
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(HeightText.Text) && String.IsNullOrEmpty(WeightText.Text))
            {
                FileNameLabel.Content = "Enter Height and Width!";
            }
            else
            {
                BrowseButton.IsEnabled = false;
                Check.IsEnabled        = false;
                Auto.IsEnabled         = false;
                Play.IsEnabled         = true;
                System.IO.DirectoryInfo di = new DirectoryInfo(searchFolder);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.InitialDirectory = "c:\\";
                dlg.Filter           = "Image files (*.jpg)|*.jpg|All Files (*.*)|*.*";
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() ?? false)
                {
                    string selectedFileName = dlg.FileName;
                    FileNameLabel.Content = "Ready!";
                    filename = selectedFileName;
                    bitmap_t.BeginInit();
                    bitmap_t.UriSource = new Uri(selectedFileName);
                    bitmap_t.EndInit();
                    Exten.Save(bitmap_t, startupPath + "\\full.jpg");
                }
                Heights = double.Parse(HeightText.Text);
                Widths  = double.Parse(WeightText.Text);
                h       = int.Parse(HeightText.Text);
                w       = int.Parse(WeightText.Text);
                List <BitmapImage> l = new List <BitmapImage>();
                int total            = h * w;
                for (int i = 0; i < total; i++)
                {
                    l.Add(Exten.ToBitmapImage(Pictures()[i]));
                    mage.Add(Exten.ToBitmapImage(Pictures()[i]));
                }


                ImageData[] images = new ImageData[total];
                for (int i = 0; i < total; i++)
                {
                    images[i] = new ImageData {
                        Images = l[i]
                    };
                }

                for (int i = 0; i < total; i++)
                {
                    string img;
                    if (i < 9)
                    {
                        img = "img0" + (i + 1) + ".jpg";
                    }
                    else
                    {
                        img = "img" + (i + 1) + ".jpg";
                    }
                    Exten.Save(mage[i], startupPath + "\\Pictures\\" + img);
                }
            }
        }