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:
parent
311b3e76f0
commit
73597689ed
16 changed files with 115 additions and 90 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
#if WINDOWS
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
|
|
@ -17,7 +18,7 @@ namespace MaddoShared;
|
|||
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
|
||||
public class ImageCreatorGDI(PicSettings picSettings, ILogger<ImageCreatorGDI> logger) : IImageCreator
|
||||
{
|
||||
public async Task CreateImageAsync(ImageState imgState, Image logo)
|
||||
public async Task CreateImageAsync(ImageState imgState, byte[]? logoData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -51,7 +52,7 @@ public class ImageCreatorGDI(PicSettings picSettings, ILogger<ImageCreatorGDI> l
|
|||
|
||||
AddText(g, imgState, imgOutputBig);
|
||||
|
||||
AddLogo(imgOutputBig, logo);
|
||||
AddLogo(imgOutputBig, logoData);
|
||||
|
||||
SavePhoto(imgOutputBig, imgState, thisFormat);
|
||||
}).ConfigureAwait(false);
|
||||
|
|
@ -480,13 +481,14 @@ public class ImageCreatorGDI(PicSettings picSettings, ILogger<ImageCreatorGDI> l
|
|||
}
|
||||
}
|
||||
|
||||
private void AddLogo(Bitmap imgOutputBig, Image logo)
|
||||
private void AddLogo(Bitmap imgOutputBig, byte[]? logoData)
|
||||
{
|
||||
// Skip if no logo provided
|
||||
if (logo is null) return;
|
||||
// Skip if no logo bytes provided
|
||||
if (logoData is null) return;
|
||||
|
||||
// Load check (use short-circuit &&)
|
||||
if (!(picSettings.LogoAggiungi && File.Exists(picSettings.LogoNomeFile))) return;
|
||||
if (!picSettings.LogoAggiungi) return;
|
||||
|
||||
using var logo = Image.FromStream(new System.IO.MemoryStream(logoData));
|
||||
|
||||
// Decide whether to apply a color-key transparency remap or rely on existing image alpha.
|
||||
// If UseTransparentColor is true, parse the configured TransparentColor and remap it to fully transparent.
|
||||
|
|
@ -861,3 +863,4 @@ public class ImageCreatorGDI(PicSettings picSettings, ILogger<ImageCreatorGDI> l
|
|||
: Environment.NewLine + formatted;
|
||||
}
|
||||
}
|
||||
#endif // WINDOWS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue