diff --git a/CommonWPF/WPFExtensions.cs b/CommonWPF/WPFExtensions.cs index 890b4b9..27a7194 100644 --- a/CommonWPF/WPFExtensions.cs +++ b/CommonWPF/WPFExtensions.cs @@ -17,10 +17,10 @@ using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; -using System.Windows.Controls.Primitives; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Imaging; namespace CommonWPF { /// @@ -263,4 +263,38 @@ namespace CommonWPF { } } } + + /// + /// BitmapSource extensions. + /// + public static class BitmapSourceExtensions { + /// + /// Creates a scaled copy of a BitmapSource. Only scales up, using nearest-neighbor. + /// + public static BitmapSource CreateScaledCopy(this BitmapSource src, int scale) { + // Simple approach always does a "blurry" scale. + //return new TransformedBitmap(src, new ScaleTransform(scale, scale)); + + // Adapted from https://weblogs.asp.net/bleroy/resizing-images-from-the-server-using-wpf-wic-instead-of-gdi + // (found via https://stackoverflow.com/a/25570225/294248) + BitmapScalingMode scalingMode = BitmapScalingMode.NearestNeighbor; + + int newWidth = (int)src.Width * scale; + int newHeight = (int)src.Height * scale; + + var group = new DrawingGroup(); + RenderOptions.SetBitmapScalingMode(group, scalingMode); + group.Children.Add(new ImageDrawing(src, + new Rect(0, 0, newWidth, newHeight))); + var targetVisual = new DrawingVisual(); + var targetContext = targetVisual.RenderOpen(); + targetContext.DrawDrawing(group); + var target = new RenderTargetBitmap( + newWidth, newHeight, 96, 96, PixelFormats.Default); + targetContext.Close(); + target.Render(targetVisual); + var targetFrame = BitmapFrame.Create(target); + return targetFrame; + } + } } diff --git a/SourceGen/Res/Strings.xaml b/SourceGen/Res/Strings.xaml index 8fd9a64..ebda1b4 100644 --- a/SourceGen/Res/Strings.xaml +++ b/SourceGen/Res/Strings.xaml @@ -89,6 +89,7 @@ limitations under the License. C# Source Files (*.cs)|*.cs CSV files (*.csv)|*.csv SourceGen projects (*.dis65)|*.dis65 + GIF images (*.gif)|*.gif HTML files (*.html)|*.html SGEC files (*.sgec)|*.sgec SourceGen symbols (*.sym65)|*.sym65 diff --git a/SourceGen/Res/Strings.xaml.cs b/SourceGen/Res/Strings.xaml.cs index b4be3ce..a427e24 100644 --- a/SourceGen/Res/Strings.xaml.cs +++ b/SourceGen/Res/Strings.xaml.cs @@ -159,6 +159,8 @@ namespace SourceGen.Res { (string)Application.Current.FindResource("str_FileFilterCsv"); public static string FILE_FILTER_DIS65 = (string)Application.Current.FindResource("str_FileFilterDis65"); + public static string FILE_FILTER_GIF = + (string)Application.Current.FindResource("str_FileFilterGif"); public static string FILE_FILTER_HTML = (string)Application.Current.FindResource("str_FileFilterHtml"); public static string FILE_FILTER_SGEC = diff --git a/SourceGen/RuntimeData/Help/visualization.html b/SourceGen/RuntimeData/Help/visualization.html index 7f1b08e..82f6788 100644 --- a/SourceGen/RuntimeData/Help/visualization.html +++ b/SourceGen/RuntimeData/Help/visualization.html @@ -101,6 +101,9 @@ the former a text entry field that accepts decimal and hexadecimal values. The range of allowable values is shown to the right of the entry field. If you enter an invalid value, the parameter description will turn red.

+

The "Export" button at the top right can be used to save a copy of +the bitmap or wireframe rendering with the current parameters.

+
Wireframe View Controls

The wireframe generator may offer the choice of perspective vs. diff --git a/SourceGen/SourceGen.csproj b/SourceGen/SourceGen.csproj index 76891de..16d0f7d 100644 --- a/SourceGen/SourceGen.csproj +++ b/SourceGen/SourceGen.csproj @@ -155,6 +155,9 @@ Export.xaml + + ExportVisualization.xaml + FindBox.xaml @@ -357,6 +360,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/SourceGen/Visualization.cs b/SourceGen/Visualization.cs index 137e40c..5a46eed 100644 --- a/SourceGen/Visualization.cs +++ b/SourceGen/Visualization.cs @@ -17,11 +17,10 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; -using System.Text; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Shapes; + using CommonUtil; using PluginCommon; diff --git a/SourceGen/WpfGui/EditVisualization.xaml b/SourceGen/WpfGui/EditVisualization.xaml index 35ac87a..939d8f6 100644 --- a/SourceGen/WpfGui/EditVisualization.xaml +++ b/SourceGen/WpfGui/EditVisualization.xaml @@ -105,6 +105,7 @@ limitations under the License. + @@ -119,6 +120,9 @@ limitations under the License. HorizontalAlignment="Left" ItemsSource="{Binding VisualizationList}" DisplayMemberPath="VisDescriptor.UiName" SelectionChanged="VisComboBox_SelectionChanged"/> +