Add color-key transparency support for logo overlays

- Allow users to select a transparent color for logo images (watermarks) via UI (checkbox, color picker, preview).
- Apply color-key transparency in both System.Drawing and ImageSharp backends: specified color in logo is made fully transparent.
- Persist transparency settings in PicSettings and SettingsDto; bind to DataModel and UI controls.
- Update logo preview to reflect transparency in real time.
- Add option to select image processing library (System.Drawing or ImageSharp) in UI and settings.
- Fix bug in SettingsService parameter loading for int/double/DateTime.
- Fully integrate color-key transparency into image processing and settings serialization.
This commit is contained in:
MaddoScientisto 2026-02-15 11:13:23 +01:00
commit 8872080741
9 changed files with 732 additions and 168 deletions

View file

@ -486,22 +486,37 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
// Load check (use short-circuit &&)
if (!(picSettings.LogoAggiungi && File.Exists(picSettings.LogoNomeFile))) return;
var logoColoreTrasparente = Color.White;
// * Load this Bitmap into a new Graphic Object
// 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.
using var grWatermark = Graphics.FromImage(imgOutputBig);
using ImageAttributes imageAttributes = new ImageAttributes();
// * The first step replace the background color with one that is transparent (Alpha=0, R=0, G=0, B=0)
var colorMap = new ColorMap
if (picSettings.UseTransparentColor)
{
// * background this will be the color we search for and replace with transparency
OldColor = logoColoreTrasparente,
NewColor = Color.FromArgb(0, 0, 0, 0)
};
Color keyColor = Color.White;
try
{
if (!string.IsNullOrWhiteSpace(picSettings.TransparentColor))
{
// ColorTranslator accepts both "#RRGGBB" and "RRGGBB"
keyColor = ColorTranslator.FromHtml(picSettings.TransparentColor);
}
}
catch
{
keyColor = Color.White;
}
var remapTable = new[] { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
var colorMap = new ColorMap
{
// background: the color we search for and replace with transparency
OldColor = keyColor,
NewColor = Color.FromArgb(0, 0, 0, 0)
};
var remapTable = new[] { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
}
// * The second color manipulation is used to change the opacity by setting the 3rd row and 3rd column to 0.3f
// Parse transparency safely (default to 100 if parsing fails)