Cross-platform: remove System.Drawing deps, add #if WINDOWS

Refactored image creation APIs to use byte[] for logo data instead of System.Drawing.Image, enabling cross-platform support. Wrapped all GDI+/Windows-specific code in #if WINDOWS and updated project files to conditionally include Windows-only dependencies. Defaulted to ImageSharp on non-Windows, and updated UI and settings to reflect platform capabilities. Application now builds and runs on Linux/macOS with Avalonia and ImageSharp, while retaining full Windows functionality.
This commit is contained in:
MaddoScientisto 2026-02-26 19:17:23 +01:00
commit 73597689ed
16 changed files with 115 additions and 90 deletions

View file

@ -5,12 +5,17 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
#if WINDOWS
using System.Drawing.Text;
#endif
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
#if WINDOWS
using System.Windows.Forms;
#endif
using System.Windows.Input;
using AutoMapper;
using MaddoShared;
@ -258,12 +263,16 @@ namespace ImageCatalog_2
private List<string> LoadAvailableFonts()
{
#if WINDOWS
var fonts = new List<string>();
using (var installedFonts = new InstalledFontCollection())
{
fonts.AddRange(installedFonts.Families.Select(f => f.Name));
}
return fonts;
#else
return new List<string>();
#endif
}
private CancellationTokenSource? _mainToken;
@ -604,7 +613,12 @@ namespace ImageCatalog_2
}
// Image library selection (UI radio buttons bind to the boolean helpers)
private string _imageLibrary = "System.Graphics";
private string _imageLibrary = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "System.Graphics" : "ImageSharp";
/// <summary>
/// Whether the application is running on Windows. Used by cross-platform UIs to show/hide Windows-only options.
/// </summary>
public bool IsRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
/// <summary>
/// The selected image processing library. Possible values: "System.Graphics" or "ImageSharp".
@ -624,6 +638,7 @@ namespace ImageCatalog_2
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(UseSystemGraphics));
NotifyPropertyChanged(nameof(UseImageSharp));
NotifyPropertyChanged(nameof(IsRunningOnWindows));
}
}
@ -1506,7 +1521,11 @@ namespace ImageCatalog_2
public event EventHandler<string> LoadSettingsRequested;
public event EventHandler SelectColorRequested;
// Request that the View shows a message to the user (message, caption, icon)
#if WINDOWS
public event EventHandler<Tuple<string, string, MessageBoxIcon>> ShowMessageRequested;
#else
public event EventHandler<Tuple<string, string, int>> ShowMessageRequested;
#endif
public event EventHandler SelectTransparentColorRequested;
private void SelectSourceFolder(object parameter)