private async void capture_Click(object sender, RoutedEventArgs e) { _photoStorageFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg(); imageProperties.Width = cameraWidth; imageProperties.Height = cameraHeight; await _mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, _photoStorageFile); await Task.Run(async () => { var ditherResult = await Dither.ditherFile(_photoStorageFile, imageProperties.Width, imageProperties.Height); _locations = Linearization.GetLocationsFromDither(ditherResult.pixels, (int)ditherResult.width, (int)ditherResult.height); if (_locations.Count > 0) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MemoryStream ms = new MemoryStream(ditherResult.pixels); var expand = new byte[ditherResult.width * ditherResult.height * 4]; for (int i = 0; i < ditherResult.pixels.Length; i++) { expand[i * 4 + 0] = ditherResult.pixels[i]; expand[i * 4 + 1] = ditherResult.pixels[i]; expand[i * 4 + 2] = ditherResult.pixels[i]; expand[i * 4 + 3] = 255; } WriteableBitmap bi = new WriteableBitmap((int)ditherResult.width, (int)ditherResult.height); expand.CopyTo(bi.PixelBuffer); ditheredImageResult.Source = bi; }); var start = DateTime.Now; _algorithm = new TravellingSalesmanAlgorithm(_startLocation, _locations.ToArray(), _populationCount); _algorithm.MustMutateFailedCrossovers = true; _algorithm.MustDoCrossovers = true; while (_currentGeneration++ < maxGenerations) { _algorithm.Reproduce(); } _bestSolutionSoFar = _algorithm.GetBestSolutionSoFar().ToArray(); Debug.WriteLine("TSP took: " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds"); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { draw.IsEnabled = true; }); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { var startLines = DateTime.Now; generateLines(); lineResult.Invalidate(); Debug.WriteLine("LineDraw " + (DateTime.Now - startLines).TotalSeconds.ToString() + " seconds"); }); }); }
private async void capture_Click(object sender, RoutedEventArgs e) { _photoStorageFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg(); imageProperties.Width = cameraWidth; imageProperties.Height = cameraHeight; await _mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, _photoStorageFile); await Task.Run(async() => { var ditherResult = await Dither.ditherFile(_photoStorageFile, imageProperties.Width, imageProperties.Height); _locations = Linearization.GetLocationsFromDither(ditherResult.pixels, (int)ditherResult.width, (int)ditherResult.height); if (_locations.Count > 0) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MemoryStream ms = new MemoryStream(ditherResult.pixels); var expand = new byte[ditherResult.width *ditherResult.height * 4]; for (int i = 0; i < ditherResult.pixels.Length; i++) { expand[i * 4 + 0] = ditherResult.pixels[i]; expand[i * 4 + 1] = ditherResult.pixels[i]; expand[i * 4 + 2] = ditherResult.pixels[i]; expand[i * 4 + 3] = 255; } WriteableBitmap bi = new WriteableBitmap((int)ditherResult.width, (int)ditherResult.height); expand.CopyTo(bi.PixelBuffer); ditheredImageResult.Source = bi; }); var start = DateTime.Now; _algorithm = new TravellingSalesmanAlgorithm(_startLocation, _locations.ToArray(), _populationCount); _algorithm.MustMutateFailedCrossovers = true; _algorithm.MustDoCrossovers = true; while (_currentGeneration++ < maxGenerations) { _algorithm.Reproduce(); } _bestSolutionSoFar = _algorithm.GetBestSolutionSoFar().ToArray(); Debug.WriteLine("TSP took: " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds"); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { draw.IsEnabled = true; }); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { var startLines = DateTime.Now; generateLines(); lineResult.Invalidate(); Debug.WriteLine("LineDraw " + (DateTime.Now - startLines).TotalSeconds.ToString() + " seconds"); }); }); }