diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/BitmapUtils.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/BitmapUtils.cs new file mode 100644 index 0000000..3bfd479 --- /dev/null +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/BitmapUtils.cs @@ -0,0 +1,67 @@ +/* + * WelsonJS.Toolkit: WelsonJS native component + * + * filename: + * BitmapUtils.cs + * + * description: + * WelsonJS - Build a Windows app on the Windows built-in JavaScript engine + * + * website: + * - https://github.com/gnh1201/welsonjs + * - https://catswords.social/@catswords_oss + * + * author: + * Namhyeon Go + * + * license: + * GPLv3 or MS-RL(Microsoft Reciprocal License) + * + */ + +using System.Drawing; + +namespace WelsonJS +{ + public class BitmapUtils + { + private static Bitmap Load(string filename) + { + return new Bitmap(filename); + } + + public static void Crop(string srcfile, string dstfile, int x, int y, int a, int b) + { + Bitmap originalBitmap = Load(srcfile); + + Rectangle cropArea = new Rectangle(x, y, a, b); + Bitmap croppedBitmap = originalBitmap.Clone(cropArea, originalBitmap.PixelFormat); + + croppedBitmap.Save(dstfile); + } + + public static int[] GetSize(string srcfile) + { + Bitmap bitmap = Load(srcfile); + + int width = bitmap.Width; + int height = bitmap.Height; + + return new int[] { width, height }; + } + + public static int[] GetPixel(string srcfile, int x, int y) + { + Bitmap bitmap = Load(srcfile); + + Color pixelColor = bitmap.GetPixel(x, y); + int red = pixelColor.R; + int green = pixelColor.G; + int blue = pixelColor.B; + + bitmap.Dispose(); + + return new int[] { red, green, blue }; + } + } +} diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs index 8c748c9..43d6061 100644 --- a/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs @@ -241,5 +241,32 @@ namespace WelsonJS HIGHT.ECB cipher = new HIGHT.ECB(userKey); return Encoding.UTF8.GetString(cipher.Decrypt(dataIn)).Trim('\0'); } + + [ComVisible(true)] + public string GetImageSize(string srcfile) + { + int[] result = BitmapUtils.GetSize(srcfile); + int width = result[0]; + int height = result[1]; + + return $"width={width}; height={height}"; + } + + [ComVisible(true)] + public string GetImagePixel(string srcfile) + { + int[] result = BitmapUtils.GetSize(srcfile); + int red = result[0]; + int green = result[1]; + int blue = result[2]; + + return $"red={red}; green={green}; blue={blue}"; + } + + [ComVisible(true)] + public void CropImage(string srcfile, string dstfile, int x, int y, int a, int b) + { + BitmapUtils.Crop(srcfile, dstfile, x, y, a, b); + } } } diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/WelsonJS.Toolkit.csproj b/WelsonJS.Toolkit/WelsonJS.Toolkit/WelsonJS.Toolkit.csproj index 1bab23d..94243b6 100644 --- a/WelsonJS.Toolkit/WelsonJS.Toolkit/WelsonJS.Toolkit.csproj +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/WelsonJS.Toolkit.csproj @@ -65,6 +65,7 @@ +