private void loadUserMediaInformation() { if (loadedPhotoData == null) { // If using the CMS - pull from that if (Properties.Settings.Default.useCMS == true) { // Blocks createCMSLink(); _cms.pullRecentlySubmittedImages(); loadedPhotoData = _cms.getLatestImageData(); destroyCMSLink(false); } else { // Not using the CMS - Pull from the hard drive loadedPhotoData = new List <photoDataObject>(); string saveDirPath = System.AppDomain.CurrentDomain.BaseDirectory + "localFiles\\submittedPhotos\\"; // put files into collection DirectoryInfo info = new DirectoryInfo(saveDirPath); FileSystemInfo[] files = info.GetFileSystemInfos(); foreach (FileSystemInfo fi in files) { if (((fi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) && (fi.Extension == ".jpg" || fi.Extension == ".JPG" || fi.Extension == ".jpeg" || fi.Extension == ".JPEG" || fi.Extension == ".png" || fi.Extension == ".PNG")) { loadedPhotoData.Add(new photoDataObject(fi.FullName.Replace("\\", "\\\\"), fi.FullName.Replace("\\", "\\\\"))); } } } } // Dispatch so everyone knows we are ready this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { if (photoLoadProgress != null) { PhotoLoadEventArgs newArgs = new PhotoLoadEventArgs(1.0, loadedPhotoData); photoLoadProgress(this, newArgs); } })); // ----> END OF THREAD/BG WORKER }
private void handlePhotoLoadProgress(object sender, PhotoLoadEventArgs e) { _allImageData = e.finalList; _pullNewPhotos = false; // Dispatch the latest list up so the main app has a copy of it if (incomingPhotoList != null) { PhotoListStateEventArgs newArgs = new PhotoListStateEventArgs(false, e.finalList); incomingPhotoList(this, newArgs); } // Pick a random image to display first selectRandomImage(); // Transition the first set of images on starting the process loadNewImages(); // transition them on - events handle the rest showNewImages(); }
/// <summary> /// Users are instructed to name files like this: /// 1_Foreground.png /// 1_Background.png /// /// 1_Background.png /// /// 2_Background_Greyscale.png /// /// 2_Foreground_Greyscale.png /// 2_Background_Greyscale.png /// /// Assuming they name them right, we assume that below. /// </summary> private void loadChromaKeyPhotos() { // Start by pulling everything in the directory List <chromaKeyImageData> loadedChromaPhotoData = new List <chromaKeyImageData>(); string saveDirPath = System.AppDomain.CurrentDomain.BaseDirectory + "localFiles\\backgroundImages\\"; // put files into collection DirectoryInfo info = new DirectoryInfo(saveDirPath); FileSystemInfo[] files = info.GetFileSystemInfos(); // Sort them by name and only use pngs var Orderedfiles = files.Where(f => f.Extension == ".png" || f.Extension == ".PNG") .OrderBy(f => f.Name); // Current item we are working on at any given time chromaKeyImageData currentChromaKeyItem = null; int currentLoop = 0; foreach (FileSystemInfo fi in Orderedfiles) { currentLoop += 1; // We actually attempt to load each file here into memory. using (WebClient webClient = new WebClient()) { webClient.Proxy = null; //avoids dynamic proxy discovery delay webClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default); try { byte[] imageBytes = null; imageBytes = webClient.DownloadData(fi.FullName); try { MemoryStream imageStream = new MemoryStream(imageBytes); BitmapImage currentImage = new BitmapImage(); currentImage.BeginInit(); currentImage.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; currentImage.CacheOption = BitmapCacheOption.OnLoad; currentImage.StreamSource = imageStream; currentImage.EndInit(); currentImage.Freeze(); imageStream.Close(); // Try and extract the index from the filename as we need it // reguardless string resultIndex = Regex.Match(fi.Name, @"\d+").Value; // If that went well we now need to know where to put this guy // Its a new entry if (currentChromaKeyItem == null) { currentChromaKeyItem = new chromaKeyImageData(); } else { // An exhisting entry // Try and extract the number if (resultIndex != "") { // Does it match our current index? int parsedIndex = int.Parse(resultIndex); if (parsedIndex != currentChromaKeyItem.Index) { // Its a new index - add the old entry to the main list loadedChromaPhotoData.Add(currentChromaKeyItem); currentChromaKeyItem = new chromaKeyImageData(); } } else { // Just going to have to assume its new. Shove the last one on the loaded data loadedChromaPhotoData.Add(currentChromaKeyItem); currentChromaKeyItem = new chromaKeyImageData(); } } // Set the index currentChromaKeyItem.Index = int.Parse(resultIndex); // OK now figure out if this is Foreground or Background if (fi.Name.ToUpper().Contains("BACKGROUND")) { // IST A BACKGROUND currentChromaKeyItem.BackgroundImageNameOnly = fi.Name; currentChromaKeyItem.BackgroundImageBM = currentImage; } else { // ITS A FOREGROUND currentChromaKeyItem.ForegroundImageNameOnly = fi.Name; currentChromaKeyItem.ForegroundImageBM = currentImage; } // OK now figure out if it needs greyscale if (fi.Name.ToUpper().Contains("GREYSCALE")) { currentChromaKeyItem.greyscale = true; } // Check if both a foreground and background are present OR this is the last item- if so add it and set the current null // for the next round ALSO check for the last item if ((currentChromaKeyItem.ForegroundImageBM != null && currentChromaKeyItem.BackgroundImageBM != null) || (currentLoop == Orderedfiles.Count())) { loadedChromaPhotoData.Add(currentChromaKeyItem); currentChromaKeyItem = null; } } catch (Exception e) { Console.WriteLine("Error loading media during chroma key load: " + e.ToString()); } } catch (WebException ex) { //do something to report the exception System.Diagnostics.Debug.WriteLine("Exception Downloading Image : " + ex.ToString()); } } } // Dispatch so everyone knows we are ready this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { if (photoLoadProgress != null) { PhotoLoadEventArgs newArgs = new PhotoLoadEventArgs(1.0, loadedChromaPhotoData); photoLoadProgress(this, newArgs); } })); // ----> END OF THREAD/BG WORKER }