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
|
|
@ -34,7 +34,7 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task CreateImageAsync(ImageState imgState, System.Drawing.Image logo)
|
||||
public async Task CreateImageAsync(ImageState imgState, byte[]? logoData)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(imgState);
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
var fileNameBig = System.IO.Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig);
|
||||
|
||||
// Draw overlays (text/logo) onto big image using ImageSharp and save
|
||||
await DrawAndSaveWithGdiAsync(imgBig, fileNameBig, imgState, logo, _picSettings.JpegQuality, isThumbnail: false).ConfigureAwait(false);
|
||||
await DrawAndSaveWithGdiAsync(imgBig, fileNameBig, imgState, logoData, _picSettings.JpegQuality, isThumbnail: false).ConfigureAwait(false);
|
||||
|
||||
// Create thumbnail if requested
|
||||
if (_picSettings.CreaMiniature)
|
||||
|
|
@ -85,7 +85,7 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
var fileNameSmall = System.IO.Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall);
|
||||
|
||||
// Draw overlays and save thumbnail via ImageSharp
|
||||
await DrawAndSaveWithGdiAsync(imgSmall, fileNameSmall, imgState, logo, _picSettings.JpegQualityMin, isThumbnail: true).ConfigureAwait(false);
|
||||
await DrawAndSaveWithGdiAsync(imgSmall, fileNameSmall, imgState, logoData, _picSettings.JpegQualityMin, isThumbnail: true).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -110,7 +110,7 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
};
|
||||
}
|
||||
|
||||
private async Task DrawAndSaveWithGdiAsync(Image<Rgba32> imgSharp, string outputPath, ImageState imgState, System.Drawing.Image logo, long quality, bool isThumbnail)
|
||||
private async Task DrawAndSaveWithGdiAsync(Image<Rgba32> imgSharp, string outputPath, ImageState imgState, byte[]? logoData, long quality, bool isThumbnail)
|
||||
{
|
||||
// Use ImageSharp drawing APIs to render text and logos and save using ImageSharp encoders.
|
||||
// Clone editable image so we don't mutate the original reference unexpectedly.
|
||||
|
|
@ -287,13 +287,12 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
|
||||
// Draw logo if provided. For compatibility with the original GDI implementation,
|
||||
// do not draw the logo on thumbnails (ImageCreatorSharp only draws logos on big images).
|
||||
if (logo != null && _picSettings.LogoAggiungi && !isThumbnail)
|
||||
if (logoData != null && logoData.Length > 0 && _picSettings.LogoAggiungi && !isThumbnail)
|
||||
{
|
||||
try
|
||||
{
|
||||
Image<Rgba32> logoImg = null;
|
||||
|
||||
// Prefer configured file if present, otherwise use the provided System.Drawing.Image instance
|
||||
if (!string.IsNullOrEmpty(_picSettings.LogoNomeFile) && File.Exists(_picSettings.LogoNomeFile))
|
||||
{
|
||||
using var logoStream = File.OpenRead(_picSettings.LogoNomeFile);
|
||||
|
|
@ -301,10 +300,7 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
}
|
||||
else
|
||||
{
|
||||
// Convert System.Drawing.Image to ImageSharp by saving to PNG in-memory to preserve alpha
|
||||
await using var ms = new MemoryStream();
|
||||
logo.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
using var ms = new MemoryStream(logoData);
|
||||
logoImg = await SixLabors.ImageSharp.Image.LoadAsync<Rgba32>(ms).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue