mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 20:21:03 +00:00
JMT
This commit is contained in:
parent
8e88761547
commit
34a9a843a4
|
@ -27,7 +27,7 @@ namespace WelsonJS
|
|||
{
|
||||
public class ProcessUtils
|
||||
{
|
||||
public static List<int> ProcessIDs = new List<int>();
|
||||
public static List<Process> ProcessList = new List<Process>();
|
||||
|
||||
public static string OpenFileDialog()
|
||||
{
|
||||
|
@ -48,12 +48,14 @@ namespace WelsonJS
|
|||
|
||||
public static int Open(string filepath)
|
||||
{
|
||||
int processId = -1;
|
||||
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
{
|
||||
filepath = OpenFileDialog();
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
{
|
||||
return -1;
|
||||
return processId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,16 +64,13 @@ namespace WelsonJS
|
|||
Process process = new Process();
|
||||
process.StartInfo.FileName = filepath;
|
||||
process.Start();
|
||||
|
||||
int processId = process.Id;
|
||||
ProcessIDs.Add(processId);
|
||||
|
||||
return processId;
|
||||
ProcessList.Add(process);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return -1;
|
||||
catch {
|
||||
processId = -1;
|
||||
}
|
||||
|
||||
return processId;
|
||||
}
|
||||
|
||||
public static bool Close(int processId)
|
||||
|
@ -79,12 +78,13 @@ namespace WelsonJS
|
|||
try
|
||||
{
|
||||
Process.GetProcessById(processId).CloseMainWindow();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WelsonJS.Serialization
|
||||
{
|
||||
public class KVSerializer
|
||||
{
|
||||
private static Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
|
||||
public void Add(string key, string value)
|
||||
{
|
||||
dict[key] = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (var x in dict)
|
||||
{
|
||||
sb.Append($"{x.Key}={x.Value}; ");
|
||||
}
|
||||
if (sb.Length > 0) sb.Length -= 2;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using WelsonJS.Cryptography;
|
||||
using WelsonJS.Serialization;
|
||||
|
||||
namespace WelsonJS
|
||||
{
|
||||
|
@ -247,21 +248,25 @@ namespace WelsonJS
|
|||
public string GetImageSize(string srcfile)
|
||||
{
|
||||
int[] result = BitmapUtils.GetSize(srcfile);
|
||||
int width = result[0];
|
||||
int height = result[1];
|
||||
|
||||
return $"width={width}; height={height}";
|
||||
var serializer = new KVSerializer();
|
||||
serializer.Add("width", result[0].ToString());
|
||||
serializer.Add("height", result[1].ToString());
|
||||
|
||||
return serializer.ToString();
|
||||
}
|
||||
|
||||
[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}";
|
||||
var serializer = new KVSerializer();
|
||||
serializer.Add("red", result[0].ToString());
|
||||
serializer.Add("green", result[1].ToString());
|
||||
serializer.Add("blue", result[2].ToString());
|
||||
|
||||
return serializer.ToString();
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
|
@ -275,7 +280,5 @@ namespace WelsonJS
|
|||
{
|
||||
BitmapUtils.Crop(srcfile, dstfile, x, y, a, b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user