SuperDesign/Source/开发辅助工具/Tools/FrmImageToIcon.cs
鑫Intel 03bcb8c5fd ### 2023-02-21更新
------
#### SuperDesign    V3.0.2302.2101
- *.[新增]全新文本编辑器,支持高亮、FTP查看和编辑、目录浏览,历史版本等众多功能。
2023-02-21 09:46:13 +08:00

72 lines
2.2 KiB
C#

using ryCommon;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace .Tools
{
public partial class FrmImageToIcon : DockContent
{
public FrmImageToIcon()
{
InitializeComponent();
RyFiles.AddDropDrag(TxtImagePath.Handle).ElevatedDragDrop += FrmImageToIcon_ElevatedDragDrop; ;
}
private void FrmImageToIcon_ElevatedDragDrop(object sender, ElevatedDragDropArgs e)
{
LoadImage(e.Files[0]);
}
private void LoadImage(string path)
{
superPictureBox1.Image = RyImage.LoadPic(path);
TxtImagePath.Text = path;
BtnConvert.Text = "立即转换";
}
private void BtnBrowser_Click(object sender, EventArgs e)
{
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
LoadImage(openFileDialog1.FileName);
}
}
private void BtnConvert_Click(object sender, EventArgs e)
{
var path = TxtImagePath.Text;
var icon= RyImage.ConvertToIcon(RyImage.LoadPic(path), true);
if (icon == null)
{
superPictureBox1.Image = null;
BtnConvert.Text = "转换失败";
return;
}
BtnConvert.Enabled = false;
//superPictureBox1.Image = icon.ToBitmap();
BtnConvert.Text = "转换成功";
var icon_path = System.IO.Path.GetDirectoryName(path) + "\\"+System.IO.Path.GetFileNameWithoutExtension(path) + ".ico";
try
{
FileStream fileStream = new FileStream(icon_path, FileMode.Create);
icon.Save(fileStream);
fileStream.Close();
RyFiles.OpenFolderGotoFile(icon_path);
}
catch
{
BtnConvert.Text = "保存失败";
}
BtnConvert.Enabled = true;
}
}
}