diff --git a/MFDSettingsManager/Models/ConfigurationModelBase.cs b/MFDSettingsManager/Models/ConfigurationModelBase.cs index e233663..4f7c144 100644 --- a/MFDSettingsManager/Models/ConfigurationModelBase.cs +++ b/MFDSettingsManager/Models/ConfigurationModelBase.cs @@ -1,6 +1,7 @@ using log4net; using MFDSettingsManager.Extensions; using System; +using System.Drawing; using System.IO; using System.Windows; using System.Windows.Media; @@ -124,30 +125,47 @@ protected virtual string GetReadableString() /// Crop the specified image /// /// + /// If true then the NEW transparency preserving crop and resize are used /// - public virtual BitmapSource CropImage(string imagePath) + public virtual BitmapSource CropImage(string imagePath, bool useNewMethod = false) { if (Enabled) { - BitmapImage src = new BitmapImage(); - src.BeginInit(); - src.UriSource = new Uri(imagePath, UriKind.Relative); - src.CacheOption = BitmapCacheOption.OnLoad; - src.EndInit(); - + var imgSource = new Uri(imagePath, UriKind.RelativeOrAbsolute); Int32Rect offSet = new Int32Rect(XOffsetStart, YOffsetStart, XOffsetFinish - XOffsetStart, YOffsetFinish - YOffsetStart); - CroppedBitmap croppedBitmap = new CroppedBitmap(src, offSet); - var noAlphaSource = new FormatConvertedBitmap(); - noAlphaSource.BeginInit(); - noAlphaSource.Source = croppedBitmap; - noAlphaSource.DestinationFormat = PixelFormats.Bgr24; - noAlphaSource.AlphaThreshold = 0; - noAlphaSource.EndInit(); - SaveImage(noAlphaSource, CacheFolder, $"X_{XOffsetStart}To{XOffsetFinish}Y_{YOffsetStart}To{YOffsetFinish}_{Opacity}"); - return noAlphaSource; + if (useNewMethod) + { + var targetImage = Image.FromFile(imgSource.LocalPath); + var reSizedImage = Resize(targetImage, new System.Drawing.Size(200, 200)); + BitmapImage src = new BitmapImage(); + src.BeginInit(); + src.UriSource = imgSource; + src.CacheOption = BitmapCacheOption.OnLoad; + src.EndInit(); + SaveImage(src, CacheFolder, $"TEST_X_{XOffsetStart}To{XOffsetFinish}Y_{YOffsetStart}To{YOffsetFinish}_{Opacity}"); + return src; + } + else + { + BitmapImage src = new BitmapImage(); + src.BeginInit(); + src.UriSource = imgSource; + src.CacheOption = BitmapCacheOption.OnLoad; + src.EndInit(); + var croppedBitmap = new CroppedBitmap(src, offSet); + var noAlphaSource = new FormatConvertedBitmap(); + noAlphaSource.BeginInit(); + noAlphaSource.Source = croppedBitmap; + noAlphaSource.DestinationFormat = PixelFormats.Bgr24; + //noAlphaSource.AlphaThreshold = 0; + noAlphaSource.EndInit(); + SaveImage(noAlphaSource, CacheFolder, $"X_{XOffsetStart}To{XOffsetFinish}Y_{YOffsetStart}To{YOffsetFinish}_{Opacity}"); + return noAlphaSource; + } } else { + Logger?.Warn($"The configuration is disabled, {GetReadableString()}"); return null; } } @@ -216,6 +234,44 @@ private string GetCacheFolderForModule() return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), $"Vyper Industries\\MFD4CTS\\cache\\{ModuleName}"); } + private Image MakeImage(byte[] byteArrayIn) + { + var ms = new MemoryStream(byteArrayIn); + var returnImage = Image.FromStream(ms); + return returnImage; + } + + private static Image Resize(Image image, + System.Drawing.Size size, bool preserveAspectRatio = true) + { + int newWidth; + int newHeight; + if (preserveAspectRatio) + { + var originalWidth = image.Width; + var originalHeight = image.Height; + var percentWidth = (float)size.Width / (float)originalWidth; + var percentHeight = (float)size.Height / (float)originalHeight; + var percent = percentHeight < percentWidth ? percentHeight : percentWidth; + newWidth = (int)(originalWidth * percent); + newHeight = (int)(originalHeight * percent); + } + else + { + newWidth = size.Width; + newHeight = size.Height; + } + Image newImage = new Bitmap(newWidth, newHeight); + using (Graphics graphicsHandle = Graphics.FromImage(newImage)) + { + graphicsHandle.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + graphicsHandle.InterpolationMode = + System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight); + } + return newImage; + } + #endregion Private helpers } } diff --git a/MFDSettingsManager/Properties/AssemblyInfo.cs b/MFDSettingsManager/Properties/AssemblyInfo.cs index a699024..6d3b309 100644 --- a/MFDSettingsManager/Properties/AssemblyInfo.cs +++ b/MFDSettingsManager/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.6.1.0")] -[assembly: AssemblyFileVersion("2.6.1.0")] +[assembly: AssemblyVersion("2.6.2.0")] +[assembly: AssemblyFileVersion("2.6.2.0")] diff --git a/MFDisplay/AuxWindow.xaml.cs b/MFDisplay/AuxWindow.xaml.cs index 67bc707..515ba8f 100644 --- a/MFDisplay/AuxWindow.xaml.cs +++ b/MFDisplay/AuxWindow.xaml.cs @@ -152,7 +152,6 @@ public void LoadImage() Close(); } IsWindowLoaded = true; - Visibility = Visibility.Visible; } } @@ -186,13 +185,12 @@ private BitmapSource GetBitMapSource(T configSource, string cacheFolder, stri Directory.CreateDirectory(cacheFolder); } filePath = Path.Combine(FilePath, configSource.FileName); - bitmapSource = configSource.CropImage(filePath); + bitmapSource = configSource.CropImage(filePath, false); } } catch (Exception ex) { Logger?.Error($"Unable to load {configSource.ToReadableString()}.", ex); - Close(); } finally { diff --git a/MFDisplay/MFDisplay.csproj.user b/MFDisplay/MFDisplay.csproj.user index 9c9b0c0..b5fcd50 100644 --- a/MFDisplay/MFDisplay.csproj.user +++ b/MFDisplay/MFDisplay.csproj.user @@ -9,7 +9,7 @@ en-US false - ShowAllFiles + ProjectFiles false diff --git a/MFDisplay/MainWindow.xaml.cs b/MFDisplay/MainWindow.xaml.cs index 89c56fe..52d8493 100644 --- a/MFDisplay/MainWindow.xaml.cs +++ b/MFDisplay/MainWindow.xaml.cs @@ -114,6 +114,7 @@ public void CreateWindows() if (newAuxWindow.IsWindowLoaded) { WindowList.Add(config.Name, newAuxWindow); + newAuxWindow.Visibility = Visibility.Visible; } else { @@ -267,7 +268,7 @@ private void ClearCache_Click(object sender, RoutedEventArgs e) { File.Delete(file.FullName); } - catch (System.Exception ex) + catch (Exception) { Logger.Warn($"Unable to delete cache file: {file.FullName}"); } diff --git a/MFDisplay/Properties/AssemblyInfo.cs b/MFDisplay/Properties/AssemblyInfo.cs index e866637..fbbcf80 100644 --- a/MFDisplay/Properties/AssemblyInfo.cs +++ b/MFDisplay/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.6.1.0")] -[assembly: AssemblyFileVersion("2.6.1.0")] +[assembly: AssemblyVersion("2.6.2.0")] +[assembly: AssemblyFileVersion("2.6.2.0")] diff --git a/MFDisplay/mfdsettings.config b/MFDisplay/mfdsettings.config index d4ae970..b3d0299 100644 --- a/MFDisplay/mfdsettings.config +++ b/MFDisplay/mfdsettings.config @@ -17,15 +17,9 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath="E:\HOTAS\TARGET\CTS\Docs\Profile JPGs" defaultConfig="BMSFalconF-16"> - - - + + + @@ -41,10 +35,10 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath @@ -52,21 +46,21 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath - - @@ -74,11 +68,11 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath - - @@ -86,10 +80,10 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath @@ -98,18 +92,28 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="_High Contrast MFDs\DCS AV8B MFD HiVis.jpg"> + filename="AWACS\DCS AWACS MFD.jpg"> + + + + + + filename="_High Contrast MFDs\DCS AWACS MFD HiVis.jpg" > + + + + + @@ -118,7 +122,7 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath @@ -127,20 +131,20 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="_High Contrast MFDs\DCS C101EB MFD HiVis.jpg"> - + - + @@ -225,7 +229,7 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath @@ -241,7 +245,7 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath @@ -288,13 +292,13 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="M-2000C\DCS M2000 MFD HC.jpg"> - - @@ -303,13 +307,13 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="M-2000C\DCS M2000 MFD WH.jpg"> - - @@ -318,13 +322,13 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="_High Contrast MFDs\DCS M2000 MFD HC HiVis.jpg"> - - @@ -333,13 +337,13 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="_High Contrast MFDs\DCS M2000 MFD WH HiVis.jpg"> - - @@ -375,7 +379,12 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath - + + + + + + @@ -384,7 +393,7 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath @@ -393,7 +402,7 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath filename="_High Contrast MFDs\DCS SA342 MFD HiVis.jpg"> @@ -418,8 +427,8 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath - - + + diff --git a/MFDisplay/test.config b/MFDisplay/test.config index 145f5e9..7fa5686 100644 --- a/MFDisplay/test.config +++ b/MFDisplay/test.config @@ -17,9 +17,9 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath="C:\Users\Scott\Downloads\" defaultConfig="TestJpg"> - - - + + + @@ -36,7 +36,7 @@ xsi:schemaLocation="http://tempuri.org/mfdsettings.xsd mfdsettings.xsd" filePath - +