拖拽进图床生成markdown图片链接工具
操作方法, 找到你的图片,拖放到程序界面. 点击复制到剪贴按钮,
则可以直接CTRL + V 粘贴到你的markdown文章中了
实现方法:
[C#] 纯文本查看 复制代码
using RestSharp;
string url = "https://sm.ms/api/upload";
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
Array array = (System.Array)e.Data.GetData(DataFormats.FileDrop);
int count = array.Length;
string md = "";
for(int i = 0;i<count;i++)
{
md+= UpdLoad(array.GetValue(i).ToString());
}
button1.Visible = true;
}
public string UpdLoad(string file)
{
var req = new RestRequest(Method.POST);
req.AddFile("smfile", file);
var restClient = new RestClient { BaseUrl = new Uri(url) };
string result = "";
restClient.ExecuteAsync<Root>(req, (response) =>
{
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
result="![图片](" +response.Data.data.url+ ")";
Log(result);
}
});
return result;
}
简单吧!
链接: https://pan.baidu.com/s/15tMUI16E50oyqblMuZY0uw 提取码: usdh
源码:https://gitee.com/nygula/ImageSystem
|