private void RandomCollage() { //Refresh user photo try { string path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; var bitmapImage = new BitmapImage(); var stream = File.OpenRead(path + "\\Resources\\temp\\temp.png"); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = stream; bitmapImage.EndInit(); stream.Close(); stream.Dispose(); ImageUser.Source = bitmapImage; } catch (NullReferenceException e) { const string error = "Could not load user photo. \n"; Console.WriteLine(error + e.Source); MessageBox.Show(error + e.Source); } //Pick random collage string randomPath = CollageMaker.GetRandomCollage(); Bitmap bitmap = new Bitmap(randomPath); ImageCollage.Source = Photo.AsBitmapImage(bitmap); bitmap.Dispose(); }