public MainWindowViewModel() { const bool useEmbeddedColorManagement = true; _mazeImage = Image.FromFile(_mazeImageFilePath, useEmbeddedColorManagement); _mazeToSolve = MazeConverter.ConvertImageToMaze(_mazeImage); var mazeImageBitmap = new Bitmap(_mazeImage); MazeImageBitmapSource = MazeRedrawnListener.BitmapToBitmapSource(mazeImageBitmap); InstantiateMazeSolutionLogicList(); }
private void SolveMazeOnThread() { // If the maze image has already been solved, this will reset it var mazeImageBitmap = new Bitmap(_mazeImage); MazeImageBitmapSource = MazeRedrawnListener.BitmapToBitmapSource(mazeImageBitmap); var mazeRedrawnListener = new MazeRedrawnListener(); try { _isBusySolving = true; // Subscribed to the event to watch the maze get solved if (WatchMazeGetSovled) { mazeRedrawnListener.Subscribe(_selectedSolverLogic, this); // Pretreatment logic is not very fun to watch _selectedSolverLogic.PreTreatmentLogics.Clear(); } _selectedSolverLogic.SolveMaze(); _selectedSolverLogic.MarkSolutionPath(); var mazeWriter = new MazeWriterUtility(MazeSolutionImageFilePath, _selectedSolverLogic.MazeToSolve); mazeWriter.SaveMazeImage(); // This should dispaly the solved path on the maze highlighted in green mazeImageBitmap = new Bitmap(mazeWriter.MazeImage); MazeImageBitmapSource = MazeRedrawnListener.BitmapToBitmapSource(mazeImageBitmap); } catch (Exception exceptionCaught) { throw exceptionCaught; } finally { _isBusySolving = false; mazeRedrawnListener.UnSubscribe(_selectedSolverLogic); const bool useEmbeddedColorManagement = true; _mazeImage = Image.FromFile(_mazeImageFilePath, useEmbeddedColorManagement); _mazeToSolve = MazeConverter.ConvertImageToMaze(_mazeImage); InstantiateMazeSolutionLogicList(); } }