private async void EditorPreview_Checked(object sender, RoutedEventArgs e) { if (EditorText.Visibility == Visibility.Visible) { try { lastDecodeResult = await decoder.decode(ASCIIEncoding.ASCII.GetBytes(EditorText.Text)); } catch { var loader = new ResourceLoader(); var warningTilte = loader.GetString("DecodeFailureTitle"); var warningMesage = loader.GetString("DecodeFailureMessage"); var ok = loader.GetString("Ok"); MessageDialog decodeFailedDialog = new MessageDialog(warningMesage, warningTilte); decodeFailedDialog.Commands.Add(new UICommand(ok)); decodeFailedDialog.DefaultCommandIndex = 0; await decodeFailedDialog.ShowAsync(); return; } } else if (EditorHex.Visibility == Visibility.Visible) { try { lastDecodeResult = await decoder.decode(EditorHex.Bytes); } catch (Exception) { var loader = new ResourceLoader(); var warningTilte = loader.GetString("DecodeFailureTitle"); var warningMesage = loader.GetString("DecodeFailureMessage"); var ok = loader.GetString("Ok"); MessageDialog decodeFailedDialog = new MessageDialog(warningMesage, warningTilte); decodeFailedDialog.Commands.Add(new UICommand(ok)); decodeFailedDialog.DefaultCommandIndex = 0; await decodeFailedDialog.ShowAsync(); return; } } cbm = CanvasBitmap.CreateFromBytes(EditorCanvas, lastDecodeResult.Bytes, lastDecodeResult.Width, lastDecodeResult.Height, DirectXPixelFormat.B8G8R8A8UIntNormalized); brush = new CanvasImageBrush(EditorCanvas, cbm) { Interpolation = CanvasImageInterpolation.NearestNeighbor }; EditorCanvas.Width = lastDecodeResult.Width; EditorCanvas.Height = lastDecodeResult.Height; EditorCanvas.Visibility = Visibility.Visible; EditorEditGrid.RowDefinitions[editorRow].Height = new GridLength(0, GridUnitType.Pixel); EditorEditGrid.RowDefinitions[2].Height = new GridLength(1, GridUnitType.Star); this.Keyboard.Visibility = Visibility.Collapsed; EditorCanvas.Invalidate(); }
private async Task LoadCanvas(int position) { // Skip other extensions var file = openFileParams.FileList[position]; if (file.FileType != ".pbm" && file.FileType != ".pgm" && file.FileType != ".ppm") { return; } // Skip corrupted formats DecodeResult result = await anymapDecoder.decode(file); imagesInfo[position] = result; if (result.Bytes == null) { return; } Double width = ApplicationView.GetForCurrentView().VisibleBounds.Width; Double height = ApplicationView.GetForCurrentView().VisibleBounds.Height; Double widthDiff = result.Width - width; Double heightDiff = result.Height - height; if (widthDiff > 0 || heightDiff > 0) { if (widthDiff > heightDiff) { result.CurrentZoom = (Single)width / result.Width; } else { result.CurrentZoom = (Single)height / result.Height; } } // Create canvas CanvasControl canvas = new CanvasControl() { Tag = result }; canvas.CreateResources += Img_CreateResources; canvas.Draw += Img_Draw; var wrapper = (FlipView.Items[position] as CanvasWrapper); wrapper.SetImageInfo(result); wrapper.Margin = new Thickness(0, 0, 0, 0); wrapper.SetCanvas(canvas); }