mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-13 13:11:03 +00:00
Add BitmapUtils.cs, Toolkit.cs and more
This commit is contained in:
parent
2edda2b710
commit
e3e68bf696
|
@ -19,7 +19,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace WelsonJS
|
namespace WelsonJS
|
||||||
{
|
{
|
||||||
|
@ -65,5 +68,46 @@ namespace WelsonJS
|
||||||
|
|
||||||
return new int[] { red, green, blue };
|
return new int[] { red, green, blue };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetBase64(string srcfile)
|
||||||
|
{
|
||||||
|
Bitmap bitmap = Load(srcfile);
|
||||||
|
MemoryStream memoryStream = new MemoryStream();
|
||||||
|
|
||||||
|
ImageFormat imageFormat;
|
||||||
|
if (srcfile.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
imageFormat = ImageFormat.Bmp;
|
||||||
|
}
|
||||||
|
else if (srcfile.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || srcfile.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
imageFormat = ImageFormat.Jpeg;
|
||||||
|
}
|
||||||
|
else if (srcfile.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
imageFormat = ImageFormat.Png;
|
||||||
|
}
|
||||||
|
else if (srcfile.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
imageFormat = ImageFormat.Tiff;
|
||||||
|
}
|
||||||
|
else if (srcfile.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
imageFormat = ImageFormat.Gif;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
bitmap.Save(memoryStream, imageFormat);
|
||||||
|
byte[] imageBytes = memoryStream.ToArray();
|
||||||
|
string base64String = Convert.ToBase64String(imageBytes);
|
||||||
|
|
||||||
|
bitmap.Dispose();
|
||||||
|
memoryStream.Dispose();
|
||||||
|
|
||||||
|
return base64String;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,10 +263,18 @@ namespace WelsonJS
|
||||||
return $"red={red}; green={green}; blue={blue}";
|
return $"red={red}; green={green}; blue={blue}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ComVisible(true)]
|
||||||
|
public string GetImageBase64(string srcfile)
|
||||||
|
{
|
||||||
|
return BitmapUtils.GetBase64(srcfile);
|
||||||
|
}
|
||||||
|
|
||||||
[ComVisible(true)]
|
[ComVisible(true)]
|
||||||
public void CropImage(string srcfile, string dstfile, int x, int y, int a, int b)
|
public void CropImage(string srcfile, string dstfile, int x, int y, int a, int b)
|
||||||
{
|
{
|
||||||
BitmapUtils.Crop(srcfile, dstfile, x, y, a, b);
|
BitmapUtils.Crop(srcfile, dstfile, x, y, a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user