private void btnPredictClick(object sender, RoutedEventArgs e) { btnPredict.Visibility = Visibility.Collapsed; saveCanvas(DOODLE_FN); //ink.Visibility = Visibility.Collapsed; string scriptoutput = runPredictScript(DOODLE_FN, PREDICT_COUNT); string latex = "default"; string labelsImageFn = "default"; int numSymbols = -1; var symbolImgFileNames = new List <string>(); using (var reader = new StringReader(scriptoutput)) { latex = reader.ReadLine(); labelsImageFn = reader.ReadLine(); numSymbols = Int32.Parse(reader.ReadLine()); for (int i = 0; i < numSymbols; i++) { string symbolImgFn = reader.ReadLine(); symbolImgFileNames.Add(symbolImgFn); } } textPred.Text = latex; listSymbolImages.Items.Clear(); foreach (var symbolImgFileName in symbolImgFileNames) { var magicImage = new MagicImage(); magicImage.Path = symbolImgFileName; listSymbolImages.Items.Add(magicImage); } string latexDocument = LATEX_PRE + latex + LATEX_POST; displayLatex(latexDocument); var processedOutputImage = new BitmapImage(new Uri(labelsImageFn, UriKind.Absolute)); imageProcess.Source = processedOutputImage; listSymbolImages.Visibility = Visibility.Visible; imageLatex.Visibility = Visibility.Visible; imageProcess.Visibility = Visibility.Visible; btnReset.Visibility = Visibility.Visible; btnPredict.Visibility = Visibility.Collapsed; PREDICT_COUNT += 1; }
/// <summary> /// 异步加载瓦片 /// </summary> /// <param name="c2p">显示中心</param> private void Build(Pixel c2p) { // 计算栅格图片 List <Patch> patchs = this.Patch(c2p); if (!MatchUtils.IsEmpty(patchs)) { this.Facade.Dispatcher.BeginInvoke(new Action(() => { UIElementCollection ware = this.Facade.Children; { bool erase = true; { Image[] tiles = ware.Cast <Image>().ToArray(); foreach (Image tile in tiles) { erase = true; { for (int i = patchs.Count - 1; i > -1; i--) { if (patchs[i].Uid.Equals(tile.Uid)) { patchs.RemoveAt(i); { erase = false; } break; } } if (erase) { // 终止加载 this.Target.Thread.Detach((MagicThread)tile.Tag); { tile.Uid = null; tile.Tag = null; } ware.Remove(tile); } } } // 释放内存 Array.Clear(tiles, 0, tiles.Length); } // 加载瓦片 Image mesh = null; { foreach (Patch patch in patchs) { ware.Add(mesh = new Image()); { mesh.Uid = patch.Uid; mesh.Width = this.Block.Wide; mesh.Height = this.Block.High; mesh.Opacity = this.Alpha / 100.0; // 瓦片位置 { Canvas.SetTop(mesh, this.Axis4y(patch.Num, patch.Row, this.Nature.Y)); Canvas.SetLeft(mesh, this.Axis4x(patch.Num, patch.Col, this.Nature.X)); } } // 异步下载 mesh.Tag = MagicImage.AsyncLoad(this.Source(patch.Num, patch.Row, patch.Col), this.Target.Memory, this.Target.Thread, new Action <ImageSource, int, int, int, Image>((data, l, r, c, tile) => { tile.Dispatcher.BeginInvoke(new Action(() => { if (!MatchUtils.IsEmpty(tile.Uid)) { if (MatchUtils.IsEmpty(data)) { try { data = this.Repair(l, r, c); } catch { data = null; } finally { if (!MatchUtils.IsEmpty(data) && data.CanFreeze) { data.Freeze(); } } } // 绘制瓦片 tile.Source = data; } })); }), new Object[] { patch.Num, patch.Row, patch.Col, mesh }); } // 释放内存 mesh = null; } } // 释放内存 patchs.Clear(); })); } }