93 lines
3.3 KiB
C#
93 lines
3.3 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using Com.Lmc.ShuiYin.One;
|
|
using Com.Lmc.ShuiYin.Two.Utils;
|
|
using Com.Lmc.ShuiYin;
|
|
|
|
namespace ShuiYinCSharp
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
SetupTestEnvironment();
|
|
|
|
Console.WriteLine("Select a test to run:");
|
|
Console.WriteLine("1. One.Test (DFT Converter with TextEncoder)");
|
|
Console.WriteLine("2. Two.Utils.TwoMain (WaterMarkDFT)");
|
|
Console.WriteLine("3. ImageWatermarkUtilMain (ImgWatermarkUtil)");
|
|
Console.Write("Enter choice (1-3): ");
|
|
|
|
string choice = Console.ReadLine();
|
|
|
|
try
|
|
{
|
|
switch (choice)
|
|
{
|
|
case "1":
|
|
Console.WriteLine("Running One.Test...");
|
|
Test.Run(args);
|
|
break;
|
|
case "2":
|
|
Console.WriteLine("Running Two.Utils.TwoMain...");
|
|
TwoMain.Run(args);
|
|
break;
|
|
case "3":
|
|
Console.WriteLine("Running ImageWatermarkUtilMain...");
|
|
ImageWatermarkUtilMain.Run(args);
|
|
break;
|
|
default:
|
|
Console.WriteLine("Invalid choice.");
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("An error occurred: " + ex.Message);
|
|
Console.WriteLine(ex.StackTrace);
|
|
}
|
|
|
|
Console.WriteLine("Done. Press any key to exit.");
|
|
Console.ReadKey();
|
|
}
|
|
|
|
static void SetupTestEnvironment()
|
|
{
|
|
string testDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestImages");
|
|
if (!Directory.Exists(testDir))
|
|
{
|
|
Directory.CreateDirectory(testDir);
|
|
}
|
|
|
|
CreateDummyImageIfNotExists(Path.Combine(testDir, "meinv.png"), "Image A", Color.LightBlue);
|
|
CreateDummyImageIfNotExists(Path.Combine(testDir, "yinhua.png"), "Image B", Color.LightGreen);
|
|
CreateDummyImageIfNotExists(Path.Combine(testDir, "444.png"), "Image C", Color.LightPink);
|
|
// 444.jpg is also used in One.Test
|
|
CreateDummyImageIfNotExists(Path.Combine(testDir, "444.jpg"), "Image C JPG", Color.LightSalmon);
|
|
}
|
|
|
|
static void CreateDummyImageIfNotExists(string path, string text, Color bgColor)
|
|
{
|
|
if (!File.Exists(path))
|
|
{
|
|
using (Bitmap bmp = new Bitmap(800, 600))
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
{
|
|
g.Clear(bgColor);
|
|
g.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, 10, 10);
|
|
g.DrawRectangle(Pens.Red, 50, 50, 700, 500);
|
|
|
|
ImageFormat format = ImageFormat.Png;
|
|
if (path.EndsWith(".jpg") || path.EndsWith(".jpeg"))
|
|
format = ImageFormat.Jpeg;
|
|
|
|
bmp.Save(path, format);
|
|
Console.WriteLine($"Created dummy image: {path}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|