Hej, chce zrobić program który będzie dodawał znak wodny (watermark) do zdjęcia, problem polega na tym że w zależności od wysokości i szerokości zdjęcia czcionka powinna mieć odpowiednią wielkość (czym większe zdjęcie tym większa czcionka) tylko mam problem z ułożeniem dpowiedniego algorytmu. poniżej dodaje mój kod (do poprawnego działania trzeba dodać w nugecie System.drawing.Common)
using System;
using System.Drawing;
using System.IO;
namespace Watermarking
{
class Program
{
public static string imagePath = "";
static void Main(string[] args)
{
Console.WriteLine("Podaj sciezke do pliku ");
imagePath = Console.ReadLine();
string sourceImagePath = imagePath;
string targetImagepath = Path.GetDirectoryName(imagePath);
targetImagepath += "\\";
targetImagepath += Path.GetFileNameWithoutExtension(imagePath) + "_watermarked";
targetImagepath += Path.GetExtension(imagePath);
//Wywolanie voida
AddWatermark(sourceImagePath, "Watermark", targetImagepath);
Console.WriteLine("Znak wodny zostal dodany");
}
public static void AddWatermark(string sourceImage, string text, string targetImage)
{
try
{
Image img = Image.FromFile(sourceImage, true);
int width = img.Width;
int height = img.Height;
int font_size = 20;
Point text_starting_point = new Point(width / 4, height / 2);
Font text_font = new Font("Helvetica", font_size, FontStyle.Bold, GraphicsUnit.Pixel);
Color color = Color.FromArgb(255, 0, 0);
SolidBrush brush = new SolidBrush(color);
Graphics graphics = Graphics.FromImage(img);
graphics.DrawString(text, text_font, brush, text_starting_point);
graphics.Dispose();
img.Save(targetImage);
img.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}